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

Issues with non-blocking raw connection

Surgeon_

Symbian Curator
Hello,

I am having issues with setting up a raw connection, with non-blocking sockets, using Game Maker Studio's built-in functions. Now, this is not a programming question, I know how to program the whole thing, but the issue is the following: The game usually has trouble connecting to a raw server when ran on my computer.

I tried it with a friend over Hamachi, and the game connected without issues and we were able to send data back and forth (in general it worked every time). However, only when the server was hosted on my computer, and when I tried to be the client, the connection would always time out (I'm giving it plenty of time, five to ten seconds).

When I try to host the server on my computer and connect from the same computer, sometimes it works but more often than not it times out again.

I tried it with many different ports, and the results were the same.

However, if I change all functions to regular, non-raw ones, it works. Also, if I change the sockets to blocking ones, it also works.

If it matters, both my friend and me are running Windows 7. The game is compiled with Game Maker: Studio Professional, Early Access v 1.99.493.

Do you know what could be causing this? Is there something about raw connections or non-blocking sockets that I'm missing? (But then again, why does it sometimes work flawlessly?)

Thanks for reading,
-Surgeon_
 

FrostyCat

Redemption Seeker
I'd suspect that you handled asynchronous connections improperly in your code, such that it would be fast enough for certain connections but too slow for anything less than that. If you never checked for a non-blocking-connected-type Networking event, that's one cue you've done something wrong.
 

Surgeon_

Symbian Curator
I'll provide more info.

This is the code both the server and the client are running at game start:
Code:
network_set_config(network_config_connect_timeout,10000);
network_set_config(network_config_use_non_blocking_socket,1);

This is how I set up the server:
Code:
socket_tcp=-1;
port_tcp=0;

while (socket_tcp<0 and port_tcp<65535) {
  port_tcp+=1;
  socket_tcp=network_create_server_raw(network_socket_tcp,port_tcp,max_clients);
  }

network_set_timeout(socket_tcp,10000,10000);

For the client I create a socket in pretty similar fashion, then try to connect with this:
Code:
network_connect_raw(socket_tcp,server_ip,server_port_tcp);

After that, the server receives a Networking event of type network_type_connect. Here I'm able to get the corresponding socket and the IP of the client.

And finally, the client receives one Networking event of type
network_type_non_blocking_connect. Trouble is, most of the time it just times out, and 10 seconds is more than enough to connect when both the client and the server are on the same machine.
 

Surgeon_

Symbian Curator
SOLVED:

Turns out that my code was OK, except for the fact that network_create_socket_ext() simply does not work. I don't know why, but the moment I switched to network_create_socket(), everything started working without any issues (I think that the _ext one reports success even if it fails).
 
Top