• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Networking problems (data)

DonMaklesso

Member
Hi guys, I've started multiplayer in my game but I've also come across several problems.
Specifically I have a problem with sending and receiving data (client can connect to the server if anything). I don't know however where my problem lies. Here's my chunk of code for object SERVER in Async - Networking:
Code:
var socketlist=ds_list_create();
  var n_id = ds_map_find_value(async_load, "id");
if n_id == server_socket
    {
    var t = ds_map_find_value(async_load, "type");
    switch(t)
        {
        case network_type_connect:
            var sock = ds_map_find_value(async_load, "socket");
            ds_list_add(socketlist, sock);
            break;
        case network_type_disconnect:
            var sock = ds_map_find_value(async_load, "socket");
            ds_map_delete(socketlist, sock);
            break;
        case network_type_data:
            //Data handling here...
            break;
        }
    }
    
  var t_buffer = buffer_create(256, buffer_grow, 1);
buffer_seek(t_buffer, buffer_seek_start, 0);
buffer_write(t_buffer , buffer_u16, 1);
buffer_write(t_buffer , buffer_string,"Hello");
//More data here...
for (var i = 0; i < ds_list_size(socketlist); i++;)
    {
    network_send_packet(ds_list_find_value(socketlist, i), t_buffer, buffer_tell(t_buffer));
    }
buffer_delete(t_buffer);

  var n_id = ds_map_find_value(async_load, "id");
if server_socket == n_id
    {
    var t_buffer = ds_map_find_value(async_load, "buffer");
if (t_buffer)="buffer" {    var cmd_type = buffer_read(t_buffer, buffer_u16 ); }
    var inst = ds_map_find_value(socketlist, sock );
    switch (cmd_type)
        {
        case (1):
            //A key has been pressed so read the keypress data from the buffer
            draw_text(612,384,t_buffer);
            instance_create_layer(306,128,"Player",obj_player_barbarian);
            break;
//        case HEALTH:
            //The player has taken a hit so remove health from them
//            break;
        //etc...
        }
    }
And for the CLIENT object (also Async - Network):
Code:
var socketlist=ds_list_create();
  var n_id = ds_map_find_value(async_load, "id");
if n_id == client_socket
    {
    //We have a new packet from the server
    }
    
  var t_buffer = buffer_create(256, buffer_grow, 1);
buffer_seek(t_buffer, buffer_seek_start, 0);
buffer_write(t_buffer , buffer_u16, 1);
buffer_write(t_buffer , buffer_string,"Hello");
//More data here...
network_send_packet(client_socket, t_buffer, buffer_tell(t_buffer));
buffer_delete(t_buffer);

  var n_id = ds_map_find_value(async_load, "id");
if SERVER.server_socket == n_id
    {
    var t_buffer = ds_map_find_value(async_load, "buffer");
if (t_buffer)="buffer" {    var cmd_type = buffer_read(t_buffer, buffer_u16 ); }
    var sock = ds_map_find_value(async_load, "socket");
    var inst = ds_map_find_value(socketlist, sock );
    switch (cmd_type)
        {
        case (1):
            //A key has been pressed so read the keypress data from the buffer
            draw_text(612,384,t_buffer);
            instance_create_layer(612,128,"Player",obj_player_marine);
            break;
//        case HEALTH:
            //The player has taken a hit so remove health from them
//            break;
        //etc...
        }
    }
(I have followed Networking Overview: https://help.yoyogames.com/hc/en-us/articles/216754698-Networking-Overview)

What am I doing wrong?
 
Top