question

demurov avatar image
demurov asked

Client disconnects with timeout after connecting to the server in Active state

Hey there,

The issue I have is that my client disconnects after 10 seconds (or any other receive timeout I set) after connecting to the server which is in Active state. My client/server is just a sample from MpsSamples repo on GitHub.

Test cases:

1. When the server is in Standby state on PlayFab MPS, the client connects to the server and keeps the connection until I disconnect it manually. However the server state is still Standby when I check it from Web console and there is no active session shown

2. When I manually make a "Request Server" call before connecting, and the server goes into Active state (active session id shows up) then the client connects to the server but disconnects after "receive timeout" seconds (the screenshot is attached)

3. When testing locally with LocalMultiplayerAgent, the connections seems to be working fine - it connects and keeps connection until the agent terminates the server

I tried different settings on PlayFab web console but nothing helped. I would really appreciate any help.

multiplayer
active.png (26.8 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gosen Gao avatar image
Gosen Gao answered

After researching the source code of the PlayFab Mirror sample, under normal circumstances, the server should start listening to the port when it is in the Active state. In your log, you can find that the server starts listening on the port in the standby state, so when the server enters the Active state, it will try to listen to the same port again, resulting in an error. Please check your code to see if any other methods call the StartListen() besides the OnServerActive().

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

demurov avatar image demurov commented ·

Thank you so much for pointing me in the right direction!

The problem was in "Auto Start Server Build" set to true in NetworkManager properties. I disabled auto start and now everything works as expected.

Please convert your comment to an answer, and I will accept it as a correct solution.

1 Like 1 ·
Gosen Gao avatar image
Gosen Gao answered

May I know how you connect to a Standby server? Since it is not active, you should not be able to get the Ip and Port info to connect to it. Usually, you need to call API RequestMultiplayerServer to turn a Standby server into Active and get the server’s detailed info including Ip and Port which you need to connect to it. Or you can turn a Standby server into Active and get the info via the Matchmaking system.

According to your description, it seems like the server doesn’t receive the request. Please check the server logs to see if you are connecting to the server correctly.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

demurov avatar image
demurov answered

@Gosen Gao

Thanks for your reply! Let me explain how I connect to the server:

1. I request a server from the web console to get IP and port for my client.

2. I connect to the server, but the client is disconnected after 10 seconds (receive timeout setting on the client). The server log doesn't contain any information about connected clients, it's basically just heartbeating:

state: PlayFab.MultiplayerAgent.Model.HeartbeatRequest, payload: {"CurrentGameState":"StandingBy","CurrentGameHealth":"Healthy","CurrentPlayers":[]}
[UnityNetworkServer].StartListen
Server: Start port=7777
NetworkServer.RegisterHandler replacing handler for Mirror.ReadyMessage, id=40252. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
NetworkServer.RegisterHandler replacing handler for Mirror.CommandMessage, id=46228. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
NetworkServer.RegisterHandler replacing handler for Mirror.NetworkPingMessage, id=33151. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
Server Started From Agent Activation
Operation: Active, Maintenance:, State: Active
Server Thread stopped. That's okay. System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address (protocol/network address/port) is normally permitted.
Timer:1.003888 - Max:1
state: PlayFab.MultiplayerAgent.Model.HeartbeatRequest, payload: {"CurrentGameState":"Active","CurrentGameHealth":"Healthy","CurrentPlayers":[]}
Operation: Continue, Maintenance:, State: Active

3. I then shutdown the server from the web console and use the same IP/port info again to connect (as I only have 1 standby server for testing, IP doesn't change). Now the client stays connected until I stop it manually and the client actually shows up in the server log:

Server: Start port=7777
ERROR: Shader UI/Default shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
Server: listening port=7777
[AgentListener].ReadyForPlayers
Timer:1.00888 - Max:1
state: PlayFab.MultiplayerAgent.Model.HeartbeatRequest, payload: {"CurrentGameState":"StandingBy","CurrentGameHealth":"Healthy","CurrentPlayers":[]}
Operation: Continue, Maintenance:, State: StandingBy
. . .
. . .

Operation: Continue, Maintenance:, State: StandingBy
Client Connected
The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object.
Timer:1.002715 - Max:1
state: PlayFab.MultiplayerAgent.Model.HeartbeatRequest, payload: {"CurrentGameState":"StandingBy","CurrentGameHealth":"Healthy","CurrentPlayers":[]}
Operation: Continue, Maintenance:, State: StandingBy
. . .
. . .

Operation: Continue, Maintenance:, State: StandingBy
Client Disconnected
Timer:1.002446 - Max:1
state: PlayFab.MultiplayerAgent.Model.HeartbeatRequest, payload: {"CurrentGameState":"StandingBy","CurrentGameHealth":"Healthy","CurrentPlayers":[]}
Operation: Continue, Maintenance:, State: StandingBy

As I said my server/client code is taken directly from MpsSamples repo. I'm really new to PlayFab and likely doing something wrong, but I can't figure out how to resolve this issue.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gosen Gao avatar image Gosen Gao commented ·
System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address (protocol/network address/port) is normally permitted.<br>

It seems that another program is already listening on that port. If you are using process, please try to use Container to test your server build to see if this issue still happens.

0 Likes 0 ·
demurov avatar image demurov Gosen Gao commented ·

I'm using containers. How can I find out who's using that port when in container mode? And how is that possible that client connects to a standing by server?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.