• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

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

C

CombatCalamity

Guest
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
 
C

CombatCalamity

Guest
Alright bug submitted. Hoping to hear good news soon.

Also edit: I meant 2.2.4, not 2.1.4
 
Last edited:

chamaeleon

Member
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]
 
Top