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

GML Finding if a Server exists

J

Jack Dixon

Guest
Hello all,
I've been trying to make a online multiplayer game and am having a little trouble. I've been using
network_connect(socket, global.ip, global.port) and whenever it cant find a server it crashes (understandingly). Would it be possible to have the game check if a server exists then tell the user if it doesn't?
Thanks.
 
H

Homunculus

Guest
I shouldn't crash. If the connection fails, it should return a number less than 0. Do you check that before trying to use any network other function?
 
J

Jack Dixon

Guest
I shouldn't crash. If the connection fails, it should return a number less than 0. Do you check that before trying to use any network other function?
No I don't think so, How would I do that?
 
H

Homunculus

Guest
How can you use network_connect and not be able to check its return value?
Code:
var connection = network_connect(socket, global.ip, global.port);

if(connection >= 0) {
//connected
}
else {
//not connected
}
 
J

Jack Dixon

Guest
Still doesn't work, results in a freeze and crash
Code:
            global.ip = obj_textbox_ip.txt
            global.port = obj_textbox_port.txt
            var connection = network_connect(network_socket_tcp, global.ip, global.port);

            if(connection >= 0) {
            room_goto(rm_boot);
            }
            else {
            scr_showNotification("Couldn't find the server!")
            }
 
H

Homunculus

Guest
global.ip = obj_textbox_ip.txt
global.port = obj_textbox_port.txt

There's not way this compiles... does the game even start?
 
J

Jack Dixon

Guest
Yes and the servers work fine. Its only when you incorrectly input an IP or port (The obj_textbox_ip.txt and obj_textbox_port.txt let the user input text), that it crashes.
 
J

Jack Dixon

Guest
The original code is in a left mouse button pressed event BTW
 
M

MarisFrance

Guest
Code:
        show_debug_message("before network_connect")
        var server = network_connect(global.client_socket , ip, 7777);
        show_debug_message("after network_connect") //NEVER happens
I'm trying to handle connection errors by typing wrong ip address or wrong port number.
And I see that function network_connect freezes my game (~50 seconds before I get error code).
Is there a way to check a server without freeze? I'd like to show a funny animation while connecting even if it fails.
 
Last edited by a moderator:
D

Drepple

Guest
I know I'm very late to this, so I doubt it's worth anything to you, but in case any others are looking around the forums for networking help: You can use
Code:
network_set_config(network_config_use_non_blocking_socket, true);
to make sure the game continues running while it's trying to connect to a server. Then you can use
Code:
network_set_config(network_config_connect_timeout, time);
where 'time' is the amount of time in milliseconds for which you want the game to try and connect after using the network_connect function. Whether the game then connects to a server or has a timeout, in either case there will be a 'network_type_connect' networking asynchronous event. The async_load map will however have an additional key ("succeeded"), which you can use to check if a connection was made. (It's equal to true on a successful connection and false on a timeout.)
 
I know I'm very late to this, so I doubt it's worth anything to you, but in case any others are looking around the forums for networking help: You can use
Code:
network_set_config(network_config_use_non_blocking_socket, true);
to make sure the game continues running while it's trying to connect to a server. Then you can use
Code:
network_set_config(network_config_connect_timeout, time);
where 'time' is the amount of time in milliseconds for which you want the game to try and connect after using the network_connect function. Whether the game then connects to a server or has a timeout, in either case there will be a 'network_type_connect' networking asynchronous event. The async_load map will however have an additional key ("succeeded"), which you can use to check if a connection was made. (It's equal to true on a successful connection and false on a timeout.)
Life Saver!
 
Top