• 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!

GMS 2.3+ issues with client sending data to server (Solved)

I am having issues with sending data to server when i press a key. For some reason the data will not send even though there is a connection to the server.
Any help would be appreciated.

here is what i got:

Client Codes:

key press - enter (Player):
Code:
buffer_seek(con_client.client_buffer, buffer_seek_start, 0);
buffer_write(con_client.client_buffer, buffer_u8, 1);
buffer_write(con_client.client_buffer, buffer_string, "Hello World");
network_send_packet(con_client.client, con_client.client_buffer, buffer_tell(con_client.client_buffer));
async - networking (con_client):
Code:
type_event = ds_map_find_value(async_load,"type");

switch(type_event)
{
    case network_type_data:
        buffer = ds_map_find_value(async_load,"buffer");
        buffer_seek(buffer,buffer_seek_start,0);
        received_packet(buffer);
        break;
}
create (con_client):
Code:
client = network_create_socket(network_socket_tcp);
connected = network_connect(client, <ip address goes here> ,20000);
show_message(connected);
client_buffer = buffer_create(1024,buffer_fixed,1);
script received_packet(Client): <<<<The Issue need to remove socket from the function
Code:
function received_packet(buffer)
{
    msgid = buffer_read(buffer, buffer_u8);

    switch(msgid)
    {
        case 1:
        var message = buffer_read(buffer, buffer_string);
        show_message(message);
        break;
    }
}
server codes:

Async networking (object: con_server):
Code:
type_event = ds_map_find_value(async_load, "type");

switch(type_event)
{
    case network_type_connect:
        socket = ds_map_find_value(async_load, "socket");
        ds_list_add(socket_list, socket);
        break;

    case network_type_disconnect:
        socket = ds_map_find_value(async_load, "socket");
        ds_list_delete(socket_list,ds_list_find_index(socket_list, socket));
        break;

    case network_type_data:
        buffer = ds_map_find_value(async_load, "buffer");
        socket = ds_map_find_value(async_load, "id");
        buffer_seek(buffer, buffer_seek_start, 0);
        received_packet(buffer, socket);
        break;
}
create (con_server):
Code:
port = 20000;
max_clients = 12;

network_create_server(network_socket_tcp,port,max_clients);

buffer = buffer_create(1024,buffer_fixed,1);
socket_list = ds_list_create();
Script received packet (server):
Code:
function received_packet(buffer, socket)
{
    msgid = buffer_read(buffer, buffer_u8);
    switch (msgid)
    {
        case 1: //hello world
            var message = buffer_read(buffer, buffer_string);
      
            buffer_seek(buffer, buffer_seek_start, 0);
            buffer_write(buffer, buffer_u8, 1);
            buffer_write(buffer, buffer_string, message);
            network_send_packet(socket, buffer, buffer_tell(buffer));
            break;
    }
}
 
Last edited:

Jman

Member
I noticed in the last code block at the bottom you have netowrk_send_packet(...) instead of network_send_packet(...).
Is that how it actually is in your code?

Also, what happens exactly when you run the code? Any errors or just no indication of anything happening?
 

Jman

Member
In the async events for both the client and the server try commenting out the buffer_seek() functions that you are calling before you pass the buffer to received_packet()

Edit: After that if it doesn't work try setting a break point in the debugger and stepping through it. That way you can see if the client is actually connecting and if the server is actually receiving.
 
Top