<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
</script>
<style type="text/css">
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
</style>
<script type="text/javascript">
gRootRelPath = "../../..";
gCommonRootRelPath = "../../..";
gTopicId = "9.2.13";
<script type="text/javascript" src="../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../whxdata/projectsettings.js"></script>
<link rel="stylesheet" type="text/css" href="../../../template/styles/topic.min.css"/>
<link rel="stylesheet" type="text/css" href="../../../template/Charcoal_Grey/topicheader.css"/>
<meta name="topic-status" content="Draft"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Networking</title>
<meta name="generator" content="Adobe RoboHelp 2019"/>
<link rel="stylesheet" href="../../../assets/css/default.css" type="text/css"/>
<meta name="rh-authors" content="Mark Alexander"/>
<meta name="topic-comment" content="Reference section for the Networking functions"/>
<meta name="rh-index-keywords" content=""/>
<meta name="search-keywords" content="Networking"/>
</head>
<body>
<div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
<div class="logo">
</div>
<div class="nav">
<div class="title" title="Networking">
<span>Networking</span>
</div>
<div class="gotohome" title="Click here to see this page in full context">
<span>Click here to see this page in full context</span>
</div>
</div>
</div>
<div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>
<h1>Networking</h1>
<p>The GameMaker Studio 2 networking functions are based on <i>sockets</i>, which is an industry standard on all platforms. With sockets, you have the ability to create both clients and servers using simple GML which allows you to create even a
single player game using the client/server model (something which will allow multiplayer to be added easily later).</p>
<p>Basically, a socket is an object which can send, receive, connect and listen to <i>ports</i> on the network. These functions deal with just TCP/IP connections, which is what the internet is based on (IPv4 to be more precise). In essence this lets you
connect one socket using an IP address (let's say 192.168.1.10) to another socket on another IP address (say 192.168.1.11). Once connected, these two sockets can send data back and forth using the <tt>network_send_*</tt> functions (like <a href="network_send_packet.htm"><tt>network_send_packet()</tt></a>)
and the dedicated asynchronous event that is triggered by them. This async event will generate a <a href="../Data_Structures/DS_Maps/DS_Maps.htm">DS map</a> containing the data received as well as other details, and you can find the complete details
in the section on the <a href="../../../The_Asset_Editors/Object_Properties/Async_Events/Networking.htm">Network Async Event</a>.</p>
<p>Instead of programs having to read and deal with every bit of network traffic coming into a machine, IP addresses also deal with ports, which are numbered from 0 to 65535. This allows each program to get only the packets of data that it's interested
in, and not everything that has been sent by every program. This also saves considerable CPU time, as it seriously cuts down on data processing, so with GameMaker Studio 2 you can also “listen” to ports. So, a server will create a socket, and
then bind it to a specific port to listen to. It will then get notified of connections, disconnections and data transfers from that socket.</p>
<p>The data "packets" themselves are made up of binary data taken from a buffer. This buffer can be created and manipulated using the GameMaker Studio 2 <a href="../Buffers/Buffers.htm">Buffer functions</a>.</p>
<p>It is worth noting that if you are creating a project for the HTML5 target, then you will not be able to use the server create functions due to browser restrictions and will have to write your own server for this platform using something like <strong>Electron </strong>or
<strong>NodeJS</strong>. Also note that if your game is cross platform and you anticipate connecting to an HTML5 instance of the game from a server running on a mobile or desktop device, then your server can only communicate to the HTML5 instance
using the Web Socket protocol (this is done using the constant <tt>network_socket_ws</tt> - see <a href="network_create_server.htm"><tt>network_create_server()</tt></a> for more information). This means that your server may have to create two sockets
on different ports, one to connect to non HTML5 targets (Android, Windows, etc...) and one to connect to the HTML5 target.</p>
<p>The following functions exist for you to use for networking:</p>
<p> </p>
<ul class="colour">
<li><a href="network_create_server.htm">network_create_server</a></li>
<li><a href="network_create_server_raw.htm">network_create_server_raw</a></li>
<li><a href="network_create_socket.htm">network_create_socket</a></li>
<li><a href="network_create_socket_ext.htm">network_create_socket_ext</a></li>
<li><a href="network_connect.htm">network_connect</a></li>
<li><a href="network_connect_raw.htm">network_connect_raw</a></li>
<li><a href="network_resolve.htm">network_resolve</a></li>
<li><a href="network_set_config.htm">network_set_config</a></li>
<li><a href="network_set_timeout.htm">network_set_timeout</a></li>
<li><a href="network_send_broadcast.htm">network_send_broadcast</a></li>
<li><a href="network_send_packet.htm">network_send_packet</a></li>
<li><a href="network_send_raw.htm">network_send_raw</a></li>
<li><a href="network_send_udp.htm">network_send_udp</a></li>
<li><a href="network_send_udp_raw.htm">network_send_udp_raw</a></li>
<li><a href="network_destroy.htm">network_destroy</a></li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="../GML_Reference.htm">GML Reference</a></div>
<div style="float:right">Next: <a href="../Web_And_HTML5/Web_And_HTML5.htm">Web</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
</body></html>