• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Networking Problem

A

Apkyesamo

Guest
Hi!

I need some help with the built in networking functions.
I'm trying to send data from the server to the client. My code looks something like this:

//Server side (async networking event)
if (type == network_type_data)
{
clientSocket = ds_map_find_value(async_load, "socket");
buffer_seek(buff, buffer_seek_start, 0);
buffer_write(buff, buffer_u8, 123);
network_send_packet(clientSocket, buff, buffer_tell(buff));​
}

And whenever I send something from a Client I get the error "network_send_packet argument 1 incorrect type (5) expecting a Number (YYGI32)"
I understand that clientSocket obviously isn't an integer, but the required argument clearly says that it needs a socket.
Could you please explain what exactly happens here, and how i would fix this? (Using GM:S 1.4)
Thanks in advance!
 
Last edited by a moderator:
I

I_S

Guest
If I'm not mistaken, I believe this is because you've set clientSocket to the "socket" key from async_load when you're in the middle of a data event. The "socket" key is only defined during a connect or disconnect event. You're trying to do this during a data event, and therefore, you're giving the first argument of network_send_packet() a variable which is undefined. The value which was the client's "socket" key during the connect event becomes the "id" key of that client during data events, until it disconnects. You'll want to give that argument the id instead of the socket.
 
Top