Communicate in a network.

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

I am trying to communicate in a network with the High level multiplayer API but I do not understand this.
I can’t use rpc or rpc_id and rset function because I have a lot of error.
This is an example:

ERROR: Node not found: Spatial
   At: scene/main/node.cpp:1382
ERROR: _process_get_node: Failed to get path from RPC: Spatial
   At: core/io/multiplayer_api.cpp:248
ERROR: Invalid packet received. Requested node was not found.
   At: core/io/multiplayer_api.cpp:194

Sorry because I am a novice in the Engine and I don’t speak very well english. Good day to you !
PS: I read the documentation several times at this web address: Doc
Thanks a lot for your help.

This is the server code:

extends Node

var server

func _ready():
	print("Server Started")
	server =
	server.create_server(53000, 5)
	get_tree().connect("network_peer_connected", self, "_new_player")
	get_tree().connect("network_peer_disconnected", self, "_disconnected_player")

func _new_player(id):
	print("New player has connected: ", id)
func _disconnected_player(id):
	print("A player left the game:" , id)
remote func _hello():
	print("Hello !")

and this is the client code:

extends Spatial

func _ready():
	print("Client Started")
	var client =
	client.create_client("", 53000)
	get_tree().connect("connected_to_server", self, "_connected")
func _connected():
remote func _hello():
	print("Ok ok ok...")

Philagia | 2019-09-23 16:57

:bust_in_silhouette: Reply From: gmaps

Try placing all the functions in the same node. I believe that RPC calls in your case don’t recognize each other. You could try placing all the functions in the same file, And separate the code with puppet/master kget_tree().is_network_server() function.

Example, joining _hello function would look like this:

remote func _hello():
    if get_tree().is_network_server():
        print("Hello !")
        print("Ok ok ok...")

I believe that problem was that you were trying to call functions across two different files with different type (Spatial and Node), without some extra parameters. So the simplest solution is to put everything in the same file for start.

Oh and I forgot, you also have to refactor the logic from _ready function, which is not as simple as hello one. You may want to allow user to manually select if he wants to be a server or client, or do it automatically e.g. try joining the game and if it fails, create it. But I suggest that you do the first one.

So you would need to create a function, and init them on some user input (let’s say if user presses “1” you call the start_server and if he presses “2” you call start_client), just a simple proof of concept, later you can put a more complex lobby interface if you decide to.

func start_client()
    print("Client Started")

func start_server()
    print("Server started")

Thank you very much, that right !
And thank you for the propose with a client or server choice at the start of the game but I want to have a dedecated server application. So I want to make this but I can’t start a godot game without the window. I did research on the Internet but can’t see. Do you can make this ?
Again a big thank you and I am sorry for my badly English.

Philagia | 2019-09-24 15:56

Ah, I didn’t realize you need a dedicated server. Have you tried this tutorial? Godot dedicated server tutorial | Tom Langwaldt's Blog

gmaps | 2019-09-24 21:23