GMS 2.3+ Networking - buffer_read returns empty string.



I'm trying to get a simple Node.JS server running with websockets a GameMaker Studio 2HTML5 client. Belowis my code

Client code, Async Networking
/// @description Insert description here
// You can write your code in this editor
show_debug_message("Client's Async_load: " + json_encode(async_load)); // Can you actually do this?

if(async_load[? "type"] == network_type_data) {
    show_debug_message("Message received:");
    var t_buffer = async_load[? "buffer"];
    buffer_seek(t_buffer, buffer_seek_start, 0);
    var t_message = buffer_read(t_buffer, buffer_text);  
    show_debug_message("m: " + t_message);
Server code (NodeJS)
const WebSocket = require('ws');

console.log('listening to 9898');
const server = new WebSocket.Server({ port: 9898 });

server.on('connection', (socket) => {
    console.log("client connected!");

    socket.on('message', (message) => {
        console.log("on message", message.toString());

        // Send message back
        socket.send('Thanks, client. Appreciate it.');
    socket.on("error", (err) => {
        console.log("Caught flash policy server socket error: ");

    socket.send('Hello client, how do you do.');
I added a button-event to send data from client to server. The message is received correctly by the server whenever I click that button. However, the message that is sent back, I can't get to read the string I sent. I do get the event, it says that the buffer is filled with a length corresponding to the length of the message. However when I use the buffer_read, I get an empty string. I tried to buffer_seek to set the pos to the start of the buffer, but to no avail. In the browser debug-tools I also see that the message is received with the text in tact. What am I missing?

Here is the output of the client when I press the "send" button on it:
Network_Test_Server.js?KMOAC=33065544:216 Sending...
Network_Test_Server.js?KMOAC=33065544:216 Client's Async_load: {"type":3,"id":0,"ip":"","port":"9898","other_port":"9898","buffer":55,"size":30}
Network_Test_Server.js?KMOAC=33065544:216 Message received:
Network_Test_Server.js?KMOAC=33065544:216 m:


Yes, I did try it, without any result unfortunatly. It also would make less sense, because from my understanding buffer_string expect a string to be zero-escaped.


I tried to get the data with another NodeJS client, and that seems to work flawlessly. Kinda stumped here :|


You need to use the "raw" version of the connecting function for that to work. There is extra material in the messages for the version that doesn't have "raw" in it.


I do think I am using the raw connecting. I'm sorry, I didn't post the code for connecting earlier. I attached this code to the Create-event of the object.

client = network_create_socket(network_socket_ws);
network_connect_raw_async(client, "", "9898");
Or is there something else I need to do for connecting?

Just for completion-sake, this is the code I use to send data from client (GM) to server (NodeJs)


// Send the message
var buff = buffer_create(11, buffer_fixed, 1)
buffer_write(buff, buffer_text, "Hello world")
network_send_raw(client, buff, buffer_tell(buff))


Still struggling with this. The weird thing is, that if I use

var t_message = buffer_read(t_buffer, buffer_u64);
It will actually output a number. I also looked into the debugmenu and can see that NodeJS is sending it as a plain string, whereas GML sends it's messages as binary.

Screenshot 2021-05-04 192248.png

Edit: I'm now at a stage that I send the exact message back as it was received ("Hello world") in the same format. You would expect that this would work, but I still can't read a buffer_string or buffer_text on the GML client :|
Last edited: