This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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:

https://www.npmjs.com/package/websocket

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 }
    });
  });
});

enter image description here

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 setnetworkmaster 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.

in Engine by (16 points)

1 Answer

+2 votes

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

by (32 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.