You are on page 1of 8

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.

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

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

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

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

(2. Net_Requeue( buffer id . ------------------------------------- . this script will send a finalization packet back to the server. This packet when received by the client with Net_Requeue() tells the client to finalize requesting it's socket. Net_Enqueue( packet id ). telling the client to request it's socket ID from the server as a form of identification. Script Return Value: The script returns a default value of 0. 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. (1.Socket Requesting Scripts -Socket requesting is a system where the server sends each client a packet.broadcats is received from another UDP server. Script Return Value: The script returns a default value of 0. packet id ). telling the server the client has successfully received it's requested socket ID on the server. Net_Inquire() can be used to process the packet received from the broadcast. -. Script Return Value: The script returns a default value of 0. 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. Used on Client) When a socket request packet sent by the server with Net_Enqueue() is received. 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. (3. Net_Dequeue( buffer id ). NetTcp_Que. Used on Server) When the finalization packet sent from a client with Net_Requeue() is received on the server.

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

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