I would like my server to listen on 3 ports. how would I do that? I already know how to make it listen on 1, but when I try and make it do more it says that I cannot put more than 1 port because every type of list I put gives an error saying it cannot be converted to type “int”
I am trying to use ENetMultiplayerPeer on three ports to get 3 commands for a simulation. there needs to be three specific ports that these commands go through. I just want the server to be able to handle 3 ports at once and read the data coming through them.
ENET does have a concept of channels that can organize messages, but if you want to consume more the one port you need three ENET instances. And if you want to use the multiplayer API with that packet peer you also need to establish each peer on a separate branch in the scene tree.
With channels you should be able to use a single packet peer and RPC on different channels.
here is an example of setting up an ENET on seperate branches.
var port:int = 5544
var ip:String = "localhost"
var smapi: = SceneMultiplayer.new()
var enet = ENetMultiplayerPeer.new()
func _ready():
var path: = self.get_path()
print(self.name, " started, putting api on node ", path)
smapi.root_path = path
match self.name:
"Server":
enet.create_server(port, 2)
"Client":
enet.create_client(ip, port)
_:
push_error(self.name, ": you done messed up")
smapi.multiplayer_peer = enet
get_tree().set_multiplayer(smapi, path)
multiplayer.peer_connected.connect(_on_peer_connected)
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
This was a server client test on a single godot game. for your application I would just create three servers on different ports and node paths.
alternative channel approach
To invoke transfer channels you specifiy functions like this
@rpc("any_peer","call_remote", "reliable",0)
zero being the desired transfer channel. and you also need to setup the channels in the server setup stage.
create_server ( int port, int max_clients=32, int max_channels=0, int in_bandwidth=0, int out_bandwidth=0 )