HTML5 [2.1.4] Websockets network_connect doesn't trigger Async Networking event

Discussion in 'GameMaker Studio 2 Community Tech Support' started by CombatCalamity, Oct 9, 2019.

  1. CombatCalamity

    CombatCalamity Member

    Joined:
    Feb 16, 2019
    Posts:
    67
    Okay, so I tried the websocket echo test.
    Code:
    client_socket = network_create_socket(network_socket_ws);
    server = network_connect(client_socket, "wss://echo.websocket.org", 443);
    
    I put show_debug_message("test"); on async networking event. When I run the HTML5 game and check the debug console, nothing appears. So this means network_connect doesn't trigger async event at all... Neither do other functions like network_send_packet, etc.

    Does anyone know what causes this?

    https://www.websocket.org/echo.html
     
  2. rmanthorp

    rmanthorp YoYo Games Staff Admin YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    300
  3. CombatCalamity

    CombatCalamity Member

    Joined:
    Feb 16, 2019
    Posts:
    67
    Yes, echo.websocket.org with a port of 80 (80 for default WS port, 443 for secure) still doesn't trigger the async event.

    I'll file a bug later:rolleyes:
     
  4. CombatCalamity

    CombatCalamity Member

    Joined:
    Feb 16, 2019
    Posts:
    67
    Alright bug submitted. Hoping to hear good news soon.

    Also edit: I meant 2.2.4, not 2.1.4
     
    Last edited: Oct 9, 2019
  5. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    976
    I have had a successful websocket test using a barebones HTML5 compiled program.

    Create Event
    Code:
    connected = false;
    alarm[0] = 5 * room_speed;
    show_debug_message("Initializing Websocket");
    socket = network_create_socket(network_socket_ws);
    network_connect_raw(socket, "echo.websocket.org", 80);
    show_debug_message("Initialization Done");
    
    Async - Networking Event
    Code:
    show_debug_message(json_encode(async_load));
    switch (async_load[? "type"]) {
        case network_type_connect:
            show_debug_message("CONNECT");
            connected = true; // NOT TRIGGERED
            break;
           
        case network_type_disconnect:
            show_debug_message("DISCONNECT");
            break;
           
        case network_type_data:
            show_debug_message("DATA [" + string(async_load[? "size"]) + " bytes]");
            buf = async_load[? "buffer"];
            buffer_seek(buf, buffer_seek_start, 0);
            var msg = buffer_read(buf, buffer_string);
            show_debug_message("Received [" + msg + "]");
            break;
           
        case network_type_non_blocking_connect:
            show_debug_message("NON-BLOCKING CONNECT");
            connected = true; // TRIGGERED
            break;
    }
    
    Alarm 0 Event
    Code:
    if (connected) {
        show_debug_message("Sending Message");
        var buf = buffer_create(1024, buffer_fixed, 1);
        var msg = "Hello, World";
        buffer_seek(buf, buffer_seek_start, 0);
        buffer_write(buf, buffer_string, msg);
        network_send_raw(socket, buf, string_length(msg));
        buffer_delete(buf);
    }
    alarm[0] = 5 * room_speed;
    
    Result
    Code:
    Initializing Websocket
    Initialization Done
    Application Surface created: w=1024, h=768
    {"type":4,"id":0,"succeeded":1,"ip":"echo.websocket.org","port":80}
    NON-BLOCKING CONNECT
    Sending Message
    {"type":3,"id":0,"ip":"echo.websocket.org","port":80,"other_port":80,"buffer":0,"size":12}
    DATA [12 bytes]
    Received [Hello, World]
    Sending Message
    {"type":3,"id":0,"ip":"echo.websocket.org","port":80,"other_port":80,"buffer":0,"size":12}
    DATA [12 bytes]
    Received [Hello, World]
    Sending Message
    {"type":3,"id":0,"ip":"echo.websocket.org","port":80,"other_port":80,"buffer":0,"size":12}
    DATA [12 bytes]
    Received [Hello, World]
    Sending Message
    {"type":3,"id":0,"ip":"echo.websocket.org","port":80,"other_port":80,"buffer":0,"size":12}
    DATA [12 bytes]
    Received [Hello, World]
    
     

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