I'm trying to make a simple multiplayer experience with Game Maker, using a local network, and the basic idea is to use Game Maker's built-in networking functions.
Using a simple client-server pattern, I want to create a server only if there is no active server in my local network. My idea is to scan all the IPs from 192.168.0.0 to 192.168.255.255 (inelegant, I know, I'll figure out a way to determine "192.168.x.x" after solving this problem, maybe looking at the subnet mask). Here is the code:
var n1 = 192;
var n2 = 168;
var n3 = 0;
var n4 = 0;
var server = -1;
var ip = "";
while(n3 <= 255 && server < 0){
ip = string(n1) + "." +
string(n2) + "." +
string(n3) + "." +
string(n4);
show_debug_message("Trying " + ip);
server = network_connect(global.socket , ip, port );
n4 += 1;
if(n4 > 255) {
n4 = 1;
n3 += 1;
}
}
if(server >= 0)
show_debug_message("Found! Here you are: " + ip);
else
show_debug_message("No IP found, man!");
And that's the problem: the first IP doesn't work, the game freezes for a minute and then all the others tries will fail, even the right one, with this error:
trying 192.168.255.254
ioctlsocket failed with error: -1
Error (0x 2736): Could not set socket option
My tries:
I tried starting with the right IP and it works, so, the connection works.
I tried lowering the timeout to one second and the effect is what I expected: after one second the first attempt fails and all the latter fail as well
Any idea to check the connection before actually try it? Thanks in advance!