KroanNL
Member
Hello,
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
Server code (NodeJS)
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:
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
GML:
/// @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);
}
JavaScript:
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: ");
console.log(err.stack)
});
socket.send('Hello client, how do you do.');
});
Here is the output of the client when I press the "send" button on it:
Code:
Network_Test_Server.js?KMOAC=33065544:216 Sending...
Network_Test_Server.js?KMOAC=33065544:216 Client's Async_load: {"type":3,"id":0,"ip":"127.0.0.1","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: