Hello,
I’m using the Transport Layer API of UNET to develop an online multiplayer mobile game (for 2 players) using a dedicated server architecture.
On client side, I have developed a mechanism to put important network messages that fails to be delivered (e.g. because connection is temporarily lost) into a queue, so that they can be resent when the client reconnects to the server. Such “important” messages are sent via a channel of QosType.ReliableSequenced.
To test the game, I simply run the server on my PC, and run the clients on two phones connected to the same WLAN as the PC. To test my “queue of undelivered messages” mechanism, I simply do the following steps on a client while the game is running:
- Temporarily deactivate Wi-Fi.
- AFTER FEW SECONDS, try to send a message while the device is offline (using NetworkTransport.Send() method).
- I see (by logging debug strings to screen) that the NetworkTransport.Send() method failed: it returned true but the out error variable is equal to NetworkError.WrongChannel. In fact, the server hasn’t received the message.
- Reactivate Wi-Fi.
- After few seconds I see (by logging debug strings to screen) that the message is resent, this time correctly: NetworkTransport.Send() returned true and the out error variable is 0. In fact, the server received the message.
So far, so good… The problem occurs if, at step 2, I don’t wait few seconds before trying to send a message, but I do it immediately after disabling Wi-Fi (after less than a second). In this case, the flow is the following:
- Temporarily deactivate Wi-Fi.
- IMMEDIATELY after deactivating Wi-Fi (after less than a second) try to send a message (using NetworkTransport.Send()).
- I see (by logging debug strings to screen) that the NetworkTransport.Send() method has completed successfully: it returned true and the out error variable is 0. But the server hasn’t received the message!
- Reactivate Wi-Fi.
- The message is not resent, because it hasn’t been put into the queue, since the call to NetworkTransport.Send() was considered successful, even if the message was not correctly delivered to the server.
Since I am using a channel of QosType.ReliableSequenced, I thought that it waited for a server acknowledgment before considering the NetworkTransport.Send() successful, but it seems not to be the case. Should I manually add acknowledgment messages to my protocol to ensure that a message has been actually delivered? Or is it a Unity bug?
If necessary, I can make a small project just to reproduce this issue. If something in this post is not clear, please ask me and I’ll try to explain better. Thank you in advance for any answer.