添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

In my game, after a client stops running his/her app for a few seconds (maybe they are watching an ad or they have the app paused), the host will disconnect them from the game:

“Couldn’t add payload of size 115 to reliable send queue. Closing connection 1 as reliability guarantees can’t be maintained.”

This is totally fine by me since clients can rejoin whenever they want. The issue is that I want a way for the client to be notified they lost connection so that I can take action (maybe display a message, maybe reconnect them automatically and reload the scene). Otherwise, they’ll be on the same scene as the host, but they won’t be updated, so it feels like the app crashed or something (when in reality they just lost connection).

For instance, if they paused the game > then lost connection > and finally unpause the game, if they are inside the same scene as the host, I want to automatically send a rejoin request to the server/host and reload the scene. This method is already implemented for clients who closed the app and rejoin from the main menu, and it works fine. I’m wondering if there’s a callback or something I can use to know when the client is not connected so that I can do the same reconnecting thing but in this specific case.

Any help is highly appreciated.

There is a ClientDisconnectedCallback. Did you try this?
https://docs-multiplayer.unity3d.com/netcode/current/components/networkmanager/index.html#client-disconnection-notifications

Yes, I tried, but, unfortunately, it doesn’t seem to be triggering. When the client comes back, it’s got no messages from the ClientDisconnectedCallback.

The fastest way to test it was on the editor, pause it for some seconds until the host kicks him out, then unpause it and there’s nothing showing up on the console, while the client (editor) is not receiving any updates.

PS: this is wild, I test it like this 4 times, and I got the disconnect message from the ClientDisconnectedCallback only 1 time.

Ok, I think I figured out something. Let’s assume, for example, that it takes the host just 10 seconds to kick the client out if his game is paused.

If the client comes back right after he’s been kicked out by the host (as soon as the host receives the “Couldn’t add payload of size 115 to reliable send queue. Closing connection 1 as reliability guarantees can’t be maintained.”), then the client does not receive the message from the ClientDisconnectedCallback yet but he is completely frozen (as he’s not receiving any updates from the host). It only gets the message after, say, 25-30 seconds have passed, which is bad as it is a big enough amount of time not to be able to play.

There is a ClientDisconnectedCallback. Did you try this?
https://docs-multiplayer.unity3d.com/netcode/current/components/networkmanager/index.html#client-disconnection-notifications

It works perfect for me. This is the best function that works on suddenly Disconnection … even Relay or Lobby can not detect … but this still can detect the Disconnect on both clients and host