Server cannot 'send_bytes' to itself

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

Hi, I am setting up a server/client environment in which the server can also be a player.

I set up the server like this:

var peer := NetworkedMultiplayerENet.new()
var result := peer.create_server(int(host_port), host_connections)
tree.set_network_peer(peer)

Later, when setting up the players I need to send some data from the client to the server, or, if on the server, from the server to the server (players are configurable/saveable by the client, like in terraria).
I am using “send_bytes” for this. On the server I get an error when I try this:

ERROR: Invalid target peer: 1
At: modules/enet/networked_multiplayer_enet.cpp:578

If I call “get_tree().multiplayer.get_network_connected_peers()” I get an empty list, which explains the above error.

So how do I go about sending data from the server to the server? I want to avoid having to put extra code in all over the place to do something different if the player is on the server.

Any ideas?

I am not sure if provided networking layer supports this, but normally you can create a client/server connection within the same program. In server player application, try creating another NetworkedMultiplayerENet as client and create a connection between client and server.

unlut | 2020-09-19 19:37