GML Finding if a Server exists

Discussion in 'Programming' started by Jack Dixon, Apr 16, 2018.

  1. Jack Dixon

    Jack Dixon Member

    Joined:
    Feb 16, 2018
    Posts:
    8
    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.
     
  2. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    738
    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?
     
  3. Jack Dixon

    Jack Dixon Member

    Joined:
    Feb 16, 2018
    Posts:
    8
    No I don't think so, How would I do that?
     
  4. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    738
    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
    }
     
  5. Jack Dixon

    Jack Dixon Member

    Joined:
    Feb 16, 2018
    Posts:
    8
    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!")
                }
    
    
     
  6. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    738
    Sorry, accidentally double posted, see below
     
  7. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    738
    global.ip = obj_textbox_ip.txt
    global.port = obj_textbox_port.txt

    There's not way this compiles... does the game even start?
     
  8. Jack Dixon

    Jack Dixon Member

    Joined:
    Feb 16, 2018
    Posts:
    8
    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.
     
  9. Jack Dixon

    Jack Dixon Member

    Joined:
    Feb 16, 2018
    Posts:
    8
    The original code is in a left mouse button pressed event BTW
     
  10. MarisFrance

    MarisFrance Member

    Joined:
    Jul 26, 2018
    Posts:
    22
    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: Aug 8, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice