lidgren-network-gen3 icon indicating copy to clipboard operation
lidgren-network-gen3 copied to clipboard

Can't connect to different ports.

Open pax83 opened this issue 10 years ago • 4 comments
trafficstars

What is the correct way to connect to different ports of the server if one port is not available because of the LAN settings?

I have server started on two ports. Connecting to first port if available is successed, but if first port not available, I can't connect to other. Connect to second port on start is also successed.

When I connecting to first port, I receive status Disconnected with message: Failed to establish connection - no response from remote host. When I connecting to second port, I receive status Disconnected with empty message.

What I tried: just second call Connect to new port; Shoutdown NetClient and create new. Same results.

I'am using Unity.

pax83 avatar Jun 23 '15 06:06 pax83

I don't quite follow you. Using NetPeerConfiguration.Port you can configure the port that a peer (for example; a server) is listening to.

lidgren avatar Jun 23 '15 07:06 lidgren

I have server with two peers:

serverPeers.Add(CreateServerPeer(address, port, maxPlayers)); serverPeers.Add(CreateServerPeer(address, alternativePort, maxPlayers));

private ServerPeer CreateServerPeer(string address, int port, int maxPlayers) { var config = new NetPeerConfiguration("SteamCraftGameServer"); config.LocalAddress = IPAddress.Parse(address); config.Port = port; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.MaximumConnections = maxPlayers; return new ServerPeer { peer = new NetServer(config) }; }

I try to connect to it from unity. It connects succesful to both separately.

_connection = ClientPeer.Connect(serverAddress, port, hailMessage); or _connection = ClientPeer.Connect(serverAddress, alternativePort, hailMessage);

I writed logic: If one port is not available, I try to connect to alternative port from the same unity application. This operation is not performed. Then I call Connect to second port (if connection to first fails), it Disconnects with empty message.

pax83 avatar Jun 23 '15 07:06 pax83

In my current case, the first port is closed by router.

pax83 avatar Jun 23 '15 07:06 pax83

@pax83 Provide a small project which reproduces the issue, please.

AgentFire avatar Oct 24 '15 11:10 AgentFire