1
\$\begingroup\$

I'm trying to connect multiple players ( godot clients) to 1 nodejs server and it's the second client would not connect. The first client connects, not the second.

All the relevant tutorials and projects that I found are written for Godot 3.0, therefore they are useless in 3.1 since 3.0 did not have support for websockets.

Any minimal multiplayer web sockets tutorial / code snippet or project, written for godot 3.1? Could you share minimal code?

Something like this won't work

extends Node

var ws = null

func _ready():
    ws = WebSocketClient.new()
    ws.connect("connection_established", self, "_connection_established")
    ws.connect("connection_closed", self, "_connection_closed")
    ws.connect("connection_error", self, "_connection_error")

    var url = "ws://localhost:8080"
    print("Connecting to " + url)
    ws.connect_to_url(url)

func _connection_established(protocol):
    print("Connection established with protocol: ", protocol)

func _connection_closed():
    print("Connection closed")

func _connection_error():
    print("Connection error")

func _process(delta):
    if ws.get_connection_status() == ws.CONNECTION_CONNECTING || ws.get_connection_status() == ws.CONNECTION_CONNECTED:
        ws.poll()
    if ws.get_peer(1).is_connected_to_host():
        ws.get_peer(1).put_var("HI")
        if ws.get_peer(1).get_available_packet_count() > 0 :
            var test = ws.get_peer(1).get_var()
            print('recieve %s' % test)
\$\endgroup\$
0

2 Answers 2

2
\$\begingroup\$

Sometime ago I found this github repo who explain to connect multiple godot 3.1 client to a nodejs server with websocket.

The github project

some useful example

It's pretty much self explanatory. I hope this will help you in your search

\$\endgroup\$
1
  • \$\begingroup\$ yup this is what im using right now. \$\endgroup\$
    – Lynob
    Commented May 13, 2019 at 17:52
1
\$\begingroup\$

The problem was simple to solve

When running multiple Godot editors it is also important to change the debugger port for one of the editors.

Both editors were trying to listen to port 6007 to find out any errors from the running game instance and this gives an error in one of the editors, like this: Error listening on port 6007

Change you debugger port by going to: Editor Settings -> Network -> Debug and change the remote port there to 6008 (or anything else than 6007)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .