Connect to Websocket Feature

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By viniguerrero

Hi guys!

I’m trying to make use of Godot 3.1’s new websocket feature alongside with a very simple nodeJS server, the server example version of this package:

And godot’s documentation for websocket client as listed here

http://docs.godotengine.org/en/latest/classes/class_websocketclient.html

I was able to succesfully connect the server and the engine itself.
But there are two problems annoying me that I have no clue on how to handle at this momment.

A. Is the way data gets inside the nodeJS server.

Whenever I transfer data from Godot to NodeJS WS Server I get weird characters even using JS’s toString() function.

Godot

    var client = WebSocketClient.new() 
    func _sendData(data):
    	client.get_peer(1).put_var(data)
   _sendData("Hello World")

NodeJS Server

const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 5000 });
wss.on('connection', function connection(ws) {
  var socketAddr = ws._socket.remoteAddress.replace("::ffff:","");
  var connectedLogMsg = 'User Connected: ' + socketAddr + " - " + new Date();
  ws.on('message', function incoming(message) {
    message = message.toString();
    console.log('Data Received: ', message);
    console.log(message);
    wss.clients.forEach(function(client) {
      try {
        // var clientMessage = JSON.parse(message);        
      } catch (err) { err }
    });
  });
});

And B. Is how to handle players instances if not using High Level Multiplayer’s Features

For instance, if we use HLM in godot we could easilly set up set_network_master for the node and only that node would be “controllable” by the current player in the session.
However when I connect through Websocket with the second client, the first client is able to control both players at once. Is there any way to bypass this logic?

Thanks in advance.
Best regards from Brazil.

:bust_in_silhouette: Reply From: Tilican

I made a package for this : https://github.com/gd-com/utils !!
You can find example here
Enjoy