NetGMS Tutorial

NetGMS is a base set of scripts that handles GameMaker:Studio's Networking
system in a simple to setup fashion. This tutorial will go through and give an
explanation of each script and it's use in the framework.
Net_Setup( tcp , udp );
Net_Setup() is the initiation script for the NetGMS framework, calling
this script defines whether TCP and UDP will be used or not, as well as the
variables used by both the TCP and UDP sides of the NetGMS framework.
Framework Global Variables Initiate By Script:
If using TCP: NetTcp_Sck, NetTcp_Bfr, NetTcp_Con,
NetTcp_Dis, NetTcp_Ipa,
NetTcp_Prt, NetTcp_Que,
NetTcp_Lst.
If using UDP: NetUdp_Sck, NetUdp_Hst, NetUdp_Bfr,
NetUdp_Ipa,
NetUdp_Prt, NetUdp_Map.
Script Arguments:
tcp : Set to true to use TCP or false to not use TCP.
udp : Set to true to use UDP or false to not use UDP.
Script Note:
The NetGMS framework will throw errors if you do not call the
Net_Setup
script. Calling this script should be done before
attempting to use any other
scripts within the framework.
Script Return Value:
The script returns a default value of 0.

Net_TcpServer( port , maxclients , buffer size );
Net_TcpServer() creates a TCP based server socket. The socket ID for
the TCP server socket is stored in the NetTcp_Sck globalvar.
Extra Assets Created By Script:
buffer : fixed size buffer of a user defined size. This buffer is
stored in the
NetTcp_Bfr globalvar.
ds_list : empty ds_list for storing connected client socket IDs.
This ds_list is
stored in the NetTcp_Lst globalvar.
ds_list : empty ds_list for storing client socket IDs for a client to
request. This
ds_list is stored in the NetTcp_Que
globalvar.

To avoid this. So attempting to call these scripts one after the other in one project will result in each socket and buffer being over written by the next call of the scripts. Script Note: This script uses dynamic memory. The socket ID for the raw client connection is stored in the NetTcp_Sck globalvar. Extra Assets Created By Script: buffer : fixed size buffer of a user defined size. Script Return Value: 1 if the server socket was successfully created. Net_TcpClient() and Net_TcpClientRaw() scripts all store their socket IDs and buffer IDs inside of the NetTcp_Sck and NetTcp_Bfr globalvars. make sure to delete the memory via Net_TcpDestory() when the sockets are no longer needed. buffer size : Size to use when creating the fixed sized buffer. buffer size ). The Net_TcpServer(). buffer size : Size to use when creating the fixed sized buffer. This will result in losing socket IDs and buffer IDs and will result in a memory leak. This buffer is stored in the NetTcp_Bfr globalvar.Script Arguments: port : Port to host the server socket on. -1 if the server socket failed to be created. Stored in the NetTcp_Ipa globalvar. maxclients : Total number of clients that can connect to the server. url / ip : The URL or IPv4 address the server is hosted on. This script can be used for connecting to a server made in C#. C++ or any other programming language you're hosting a server on. Stored in the NetTcp_Prt globalvar. Net_TcpClientRaw( port . Script Notes: . Stored in the NetTcp_Prt globalvar. call Net_TcpDestroy() before calling the next script. url / ip . Net_TcpClientRaw() creates a raw based TCP client connection to a server application not created with GameMaker: Studio. Script Arguments: port : Port to create the raw client connection on(server port?).

Extra Assets Created By Script: buffer : fixed size buffer of a user defined size.3. buffer size : Size to use when creating the fixed sized buffer. Note: The client socket is no longer needed as of GMS update v1. The server socket receives data while the client socket sends data. Net_TcpClient() creates a TCP based client connection to a server created in GameMaker: Studio. The socket ID for the raw client connection is stored in the NetTcp_Sck globalvar. Script Return Value: 1 if the raw client socket was successfully created. url / ip : The URL or IPv4 address the server is hosted on. buffer size ). url / ip . -1 if the client socket failed to be created. Script Arguments: port : Port to create the client connection on(server port?). buffer size ). -1 if the raw client socket failed to be created. This buffer is stored in the NetTcp_Bfr globalvar. The UDP client socket is stored in NetUdp_Sck globalvar and the UDP server socket is stored in NetUdp_Hst globalvar. The UDP scripts will be changed in the future for the v1.3. maxclients . ds_map : ds_map for holding the IP address and server name of servers found using broadcasting. Stored in the NetTcp_Prt globalvar. Script Return Value: 1 if the client socket was successfully created.1344. use the Net_TcpClientRaw() for raw client functionality. Net_TcpClient( port . Script Notes: See the Net_TcpServer() script for notes for this script.See the Net_TcpServer() script for notes for this script. Net_UdpServer( port . url / ip . This buffer is stored in the NetUdp_Bfr globalvar. Broadcasting is done via . Net_UdpServer() creates a UDP server socket as well as a UDP client socket. Extra Assets Created By Script: buffer : fixed size buffer of a user defined size. Stored in the NetTcp_Ipa globalvar. This script cannot be used to create a raw client socket.1344 update.

However. NetTcp_Lst and NetTcp_Que. The ds_List. Net_TcpDestroy(). the script also handles receiving client connections and removing clients from the server as they disconnect. NetTcp_Lst. The user defined script here should be used to identify packets and process those packets accordingly. Script Arguments: script id : User defined script that will be used to pass to and process the received data. Script Notes: When a client connects. url / ip : The URL or IPv4 address to host the server on. set to 0. The data passed in order: buffer ID. the data is passed to a custom user inputted script via "script id". maxclients : UDP servers do not support client connections. Script Notes: This script uses dynamic memory. Net_Handle( script id ). buffer size : Size to use when creating the fixed sized buffer. This NetUdp_Map globalvar. -1 if the client and server sockets failed to be created. Script Return Value: The script returns a default value of 0. ds_map is stored in the Script Arguments: port : Port to host the UDP sever on. Stored in the NetUdp_Ipa globalvar. and Net_UdpDestroy(). make sure to delete the memory via Net_UdpDestory() when the sockets are no longer needed. buffer size and packet ID. Net_Handle() handles receiving all data from TCP and UDP sockets. stores the socket ID of each client until each .NetUdp_Cast(). Stored in the NetUdp_Prt globalvar. Script Return Value: 1 if the client and server sockets were successfully created. When data is received. the client's socket ID is stored in two ds_lists. Net_TcpDestroy() and Net_UdpDestroy() will delete and reset all the dynamic memory and variables used by the server and client creation scripts.

" in them will receive this packet. stores the ID of each client until the client requests it's socket ID via Socket Requesting. The ds_list.client disconnects. Net_UdpCast( packet id . Script Return Value: The script returns a default value of 0.145. If a .145. NetTcp_Que. server name ). an IP address of "192. Net_Analyze() checks the current connection of a client to a server to see if the connection is still valid.2.x" meaning that all IP addresses with "192. Script Return Value: The script returns a default value of 0. For example.122'' has a subnet of "192. Script Return Value: 1 if the connection is still valid and -1 if the conneciton has been lost. Net_Analyze( packet id ). Net_Inquire( buffer id ). Net_Bytes( buffer id ).2. This script is a simple rename and pass through for GameMaker: Studio's buffer_tell( buffer id ) function.2. Net_Bytes() returns the total number of bytes written to the buffer from the current seek position of the buffer. Net_Inquire() this script is a followup script to Net_UdpCast(). The subnet/ip address is that of the UDP socket created by Net_UdpServer(). Net_UdpCast() creates a basic packet with a packet ID(message id/msgid) with the name of the server attached to the packet and sends(broadcasts) the packet to a range of IP addresses under the same subnet. socket Script Return Value: The script returns a default value of 0. server name : The name(as string) of the UDP server sending the broadcast. Script Arguments: packetid : The ID of the packet being broadcast.145.

Net_Inquire() will read the server name from the buffer and get the IP address of the server and store it in the NetUdp_Map ds_map with server name as the key and IP address as the value. this script will send a finalization packet back to the server. Net_Dequeue( buffer id ). This packet when received by the client with Net_Requeue() tells the client to finalize requesting it's socket. Used on Client) When a socket request packet sent by the server with Net_Enqueue() is received. Script Return Value: The script returns a default value of 0. ------------------------------------- . Net_Requeue( buffer id . telling the client to request it's socket ID from the server as a form of identification. (3. Used on Server) Loops through all of the non-requested sockets in the NetTcp_Que ds_list on the server and sends a verification packet to each socket. Used on Server) When the finalization packet sent from a client with Net_Requeue() is received on the server. (2.Socket Requesting Scripts -Socket requesting is a system where the server sends each client a packet. packet id ). Script Return Value: The script returns a default value of 0. Net_Enqueue( packet id ). -. Net_Inquire() can be used to process the packet received from the broadcast. this script will remove the client's socket ID from the socket request ds_lsit. Script Return Value: The script returns a default value of 0.broadcats is received from another UDP server. (1. NetTcp_Que. telling the server the client has successfully received it's requested socket ID on the server. Script Return Value: The script returns a default value of 0.

udp_asset_msx(size of NetUdp_Map) : Size of list in asset udp_asset_map. tcp_asset_prt(NetTcp_Prt) : Port the client(raw client) socket is connected on. tcp_asset_dis(NetTcp_Dis) : Last client socket ID to disconnect from the server. udp_asset_prt(NetUdp_Prt) : Port the server is hosted on. tcp_asset_ipa(NetTcp_Ipa) : IP address the client(raw client) socket is connected to. tcp_asset_qsz(size of NetTcp_Que) : (Server) Size of list in asset tcp_asset_que. udp_asset_ipa(NetUdp_Ipa) : URL / IP the server is hosted on. tcp_asset_lsz(size of NetTcp_Lst) : (Server) Size of list in asset tcp_asset_lst. Net_UdpAssets() returns the value of the specified asset via asset id. udp_asset_hst(NetUdp_Hst) : UDP "server" socket. tcp_asset_con(NetTcp_Con) : Last client socket ID to connect to the server. Net_UdpAssets( asset id ). Extra Constants: network_error(-1) : used for checking if a socket has an error. network_noerror(1) : used for checking if a socket has no error. udp_asset_bfr(NetUdp_Bfr) : Server buffer ID. udp_asset_map(NetUdp_Map) : ds_map of servers foudn with broadcasting. List of Assets: (asset IDs -> defined constants) tcp_asset_sck(NetTcp_Sck) : Server / Client socket ID. List of Assets: (asset IDs -> defined constants) udp_asset_sck(NetUdp_Sck) : UDP "client" socket.Net_TcpAssets( asset id ). . tcp_asset_que(NetTcp_Que) : (Server) List ID of unrequested client socket IDs. tcp_asset_lst(NetTcp_Lst) : (Server) List ID of client sockets connected to the server. Net_TcpAssets() returns the value of the specified asset via asset id. tcp_asset_bfr(NetTcp_Bfr) : Server / Client buffer ID.

msg_analyze(255) : preset packet ID for validing the connection to the server. triggered_udp(1) : used for checking if UDP received a packet. triggered_tcp(0) : used for checking if TCP received a packet.msg_queue(253) : preset packet id used for socket requesting. msg_broadcast(254) : preset packet id used for broadcasting. .