question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot send Named Message to Client Prior to Disconnect

See original GitHub issue

Describe the bug In BossRoom, we sometimes need to just boot players (for example, if a different client joins with the same GUID). When we do this, we would first like to send an explanation message to the affected client. We attempted to do this like so:

MLAPI.Messaging.CustomMessagingManager.SendNamedMessage("ServerToClientSetDisconnectReason", clientId, buffer, NetworkChannel.Internal);
NetworkManager.Singleton.DisconnectClient(clientId);

However, this doesn’t work. The connection is severed immediately, and messages that are currently outstanding are not sent. Our expectation is that we’d be able to sequence these two events (sending a message and then disconnecting) without needing a coroutine workaround.

To Reproduce Steps to reproduce the behavior:

  1. In the BossRoom demo, go to ServerGameNetPortal.cs and replace StartCoroutine(WaitToDisconnectClient) with the contents of WaitToDisconnectClient (minus the WaitForSeconds call of course).
  2. Build a non-develop version of the game, start host, and enter game.
  3. Start two clients and have them late join.
  4. Observe that the 2nd client boots the first, but that the message explaining WHY it is booted is lost. He should get an explicit message saying “You have logged in elsewhere using the same account”

Actual outcome Named Message sent just prior to disconnecting client is lost on disconnect.

Expected outcome All messages sent on a reliable channel prior to a disconnect should be delivered.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: e.g. Windows 10
  • Unity Version: 2020.3.0f1
  • MLAPI Version: 0.1.0
  • MLAPI Commit: tag release/0.1.0

Additional context Add any other context about the problem here. Logs, code snippets would be useful here but please also consider attaching a minimal Unity project that reproduces the issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
luismasuellicommented, Jul 26, 2021

Any progress with this one? I’m having the same issue as of today. I can implement some sort of workaround in my game, but still a dirty approach.

0reactions
JesseOlmercommented, Aug 23, 2022

There are two changes relevant to this.

The first is the Connection Approval process can now be resolved asynchronously, giving you several frames to send messages. https://docs-multiplayer.unity3d.com/netcode/current/basics/connection-approval#networkmanagerconnectionapprovalresponse

The other is that the default transport (Unity Transport) now flushes the message send queue before sending a disconnect message, so you don’t have to manually “wait a bit” between your send and your disconnect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot send Named Message to Client Prior to Disconnect
My current thought is that the client receives the custom message but doesn't get a chance to process the custom message since the...
Read more >
How to send message with connect or disconnect
Hi, I am currently working on a master server using the NetworkServerSimple, and I do not understand why we can not send messages...
Read more >
How to send message on django channel to all users ...
i am trying to send a message to all users before a client disconnects(when client leaves the page). def disconnect(self, close_code): ...
Read more >
Understanding and Handling Connection Lifetime Events ...
This article provides an overview of the SignalR connection, reconnection, and disconnection events that you can handle, and timeout and ...
Read more >
MQTT - AWS IoT Core
If a client doesn't reconnect to its persistent session before it expires, the session ends and its stored messages are discarded. When a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found