• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Receiving packets from an undefined socket

D

DAvideEHH

Guest
Hello! I'm doing a multiplayer game. In the Async Networking event of my object oServer i switch the EventType received so to know to do:

Code:
var ClientSocket = async_load[? "socket"]
switch(async_load[? "type"]){
     case network_type_connect:
          //do something

     case network_type_disconnect:
          //do something

     case network_type_data:
          var Buffer = async_load[? "buffer"];
          //do something else....
}
I don't know exactly when but once the server started, the server receives a network_type_data event and the buffer contains a buffer_u8 with value 2. I tryied to see the socket that sended the buffer but async_load[? "socket"] returns undefined.
This happens only one time luckily, but why? I resolved this by checking if the socket is different from undefined.
 

Tthecreator

Your Creator!
That seems to be a bug in game maker then... weird. Are you actually receiving sensible data on that undefined socket?
 
H

hyltonne

Guest
IIRC the way it works for the server is that async_load[? "socket"] is defined when async_load[? "type"] is either network_type_connect or network_type_disconnect.
otherwise, when async_load[? "type"] is network_type_data, the client socket will be in async_load[? "id"]. Therefore, your code should like something like this. I have a server socket assigned to the variable "serverSocket", and a ds list called "clients" where client sockets are added and removed:

Code:
var identifier = async_load[? "id"];
var type = async_load[? "type"];

if(identifier == serverSocket) {
    var socket = async_load[? "socket"];
  
    switch(type) {
        case network_type_connect:
            ds_list_add(clients, socket);
            break;
      
        case network_type_disconnect:
            ds_list_delete(client, ds_list_find_index(clients, socket));
            break;
    }
} else if(ds_list_find_index(clients, identifier) != -1) {
    switch(type) {
        case network_type_data:
            var buffer = async_load[? "buffer"];
            break;
    }
}
 
Last edited by a moderator:
Top