OFFICIAL Beginners Guide To Networking

rmanthorp

YoYo Games Staff
Admin
YYG Staff
Our latest tech blog is our Beginners Guide To Networking. Check it out:

In this article we aim to cover the basics of the Networking functions in GameMaker Studio 2. This article is a basic overview of how to set up a networked game using sockets, and is intended for intermediate users who are already familiar with GML (the GameMaker Language). This article will not tell you how to set up a MMO, and be aware that working with networking on any platform can be very frustrating and you will need time and patience to get it working, especially if it is new to you (even the big companies often sub-contract the networking multi-player parts of their games out to other specialised companies to write!). Generally, don't be too ambitious when starting out and test all the networking parts of your game constantly to avoid any unexpected errors later on.
https://www.yoyogames.com/blog/529/beginners-guide-to-networking
 

FrostyCat

Member
Copywriting note: In future articles featuring code, watch out for curly double quotes like this seeping in due to AutoCorrect:
Code:
buffer_write(t_buffer , buffer_string,”Hello”);
The GMS IDE recognizes only straight double quotes, and will not accept strings delimited this way.
 

Arconious

Member
Thanks for the article! In the "Detect Client Connection" section, I believe the example code for the disconnect handling is erroneous and should be
Code:
ds_list_delete(socketlist, ds_list_find_index(socketlist, sock));
 
Love these networking articles!

Will there be articles on client prediction and anti hack? Or are those topics a bit too advanced?
 

Zhanghua

Member
There is a question on the data recieving....
Tcp socket has two type, one for listenning and one for data transferring.
Code shoud like this?
Code:
var ev_id = ds_map_find_value(async_load, "id");
var type = ds_map_find_value(async_load, "type");//
var ip    = ds_map_find_value(async_load, "ip");//
if( lstn == ev_id ){//check whether the listen socket
    switch(type){
        case network_type_connect:
        case network_type_non_blocking_connect:
            var clnt = ds_map_find_value(async_load, "socket");//Save the data transferring socket
            show_debug_message(string(ip)+":"+string(port)+"Conneted-----------" + string(clnt));
            Client_Info[? clnt] = "";
            Client_Ids[? clnt]  = baseid++;
        break;
        case network_type_disconnect:
            var clnt = ds_map_find_value(async_load, "socket");
            show_debug_message(string(ip)+":"+string(port)+"Disconneted-----------" + string(clnt));
            ds_map_delete(Client_Info,clnt);
            ds_map_delete(Client_Ids,clnt);
        break;
    }
}
else{//Data from client
    if( undefined != ds_map_find_value(Client_Ids,ev_id) ){
        var clnt = ev_id;
        switch(type){
            case network_type_data:
                var buff = ds_map_find_value(async_load, "buffer");
                var size = ds_map_find_value(async_load, "size");
                var str  = buffer_read(buff,buffer_string);
                var cid  = Client_Ids[? clnt];
                Client_Info[? clnt] = string(ip)+":"+string(port)+"="+str;
                show_debug_message("Tcp Data" + string(cid) + "=" +str);
            break;
        }       
    }
}
 

Zhanghua

Member
Our latest tech blog is our Beginners Guide To Networking. Check it out:



https://www.yoyogames.com/blog/529/beginners-guide-to-networking
Is there an error of Mark Alexander‘s paper ????
So I can't translate this paper with the corespond doubt.....
Cause in my project, I realized this by method like the replied post above.


The recent essays on BLEND MODE have translated into chinese:
https://www.bilibili.com/read/cv3806331
https://www.bilibili.com/read/cv3807613
 

Ablationer

Member
I'm having an issue with this example where I can use it to connect to a network in local, however if someone else tries to connect over the internet, it doesn't work. I've tried changing global.connectip to my actual public address, but nothing.
 

Zhanghua

Member
I'm having an issue with this example where I can use it to connect to a network in local, however if someone else tries to connect over the internet, it doesn't work. I've tried changing global.connectip to my actual public address, but nothing.
NAT
 
Top