MANUAL for GMnet PUNCH
To create the udphp client with udphp_createClient you need a UDP socket (not server!), a buffer, as well as the server ip. The rest is explained in the argument listing: _How to use udphpcreateClient (arguments):
IMPORTANT: The function will return the client id you have to store. This id is used to identify this client. Using this you can run multiple clients in one game (as used in the demo). It will return -1 if the client could not be created.
buffer = buffer_create(256, buffer_grow, 1);
client = network_create_socket(network_socket_udp);
client_id = udphp_createClient(client,server_ip,buffer,false,1234);
if (client_id < 0) {
//Client could not be created. Destroy instace. GMnet PUNCH will also show a message if not silent.
instance_destroy();
}
`
In the step event simply run udphp_clientPunch with the stored client id as argument. This function will return false if the client’s connection failed. This is the only way to determine if a connection process failed and it will return true in all other cases.
if (!udphp_clientPunch(client_id)) {
//When this returns false, the connection failed or the client was destroyed.
show_message("Connection failed!");
instance_destroy();
}
`
In the networking event simply call udphp_clientNetworking with the client id as an argument.
To communicate with the server after you are connected you of course need IP and port of the server, you also need to know if you are already connected. To do that use these functions:
var connected = udphp_clientIsConnected(client_id); //true or false
if (connected) {
//The next functions will return invalid information if you use them without making sure you are connected:
var ip = udphp_clientGetServerIP(client_id); //String
var port = udphp_clientGetServerPort(client_id); //real
}
Please see the hello world demo scripts in obj_client for an example.
In the next page we will show the last feature: The online lobby!
» Next topic: Done!
« Previous topic: Server
All pages in this manual are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
GameMaker: Studio is owned by YoYoGames. GMnet is not affiliated with YoYoGames.
The GMnet logos use icons from Entypo (http://entypo.com/) and Open Iconic (https://useiconic.com/open/). They are licensed under CC BY-SA 4.0.