Closed pooyakn closed 7 years ago
Hey @Starless-Sky Thanks for reporting this. I've confirmed the behaviour and the value of the callback is indeed always true
. This value comes directly from WebsocketSharp (WS#). I've even tried to use whats on the master branch of WS# and this behaviour still persists.
There are two behaviours to note:
Send()
method.On the Unity Editor, Android and iOS these are not invoked when the client has disconnected. The reason for this is that there is a buffer in the underlying .net Socket object called SendBufferSize
. The default size of SendBufferSize
on the Unity Editor is 131328
and on Android is 6291456
(iOS is unknown). When sending a message while disconnected, the message is buffered up and released only when you are reconnected to the network.
I've tried setting the SendBufferSize
to really small values (0
, 1
and 128
) but they have various undesired effects for both normal and disconnected states (for instance, in iOS, once the buffer fills up, the app crashes and never comes back up again).
We've spoken internally and have decided to leave the default values here. This means that in a situation where disconnection happens, neither supplied callbacks are invoked. Further details below.
This is different on the three tested platforms. Under the test condition (connected to the server, and manually disconnected), the observed behaviour is as follows:
I've tried digging for more information as to why this behaviour is different but sadly I've not reached any conclusions.
Therefore, I've concluded from my research that this is a platform limitation, and on Unity Editor it is probably a limitation/bug in Mono/UnityEngine.
Given that this behaves relatively well on end user devices, we'll leave the functionality as it is and mention this caveat in the Unity documentation.
I'll close this ticket now, but feel free to reopen if you have more information about this.
@mofirouz so can we consider the SendAsync function will always return completed == true to indicate the server/receiver has received the message/data no matter whether it's sent successfully or no?
Hi. It's an issue that is discussed in Gitter. Post it here just for reference. This is what I tested: I started a match, disabled my internet connection, and sent a message to the match. Surprisingly completed callback got called with the value of true. I waited for OnDisconnected to get called, but after 60 seconds it didn't. So I turned internet connection back on, and then OnDisconnected fired. Also found a similar issue here: https://github.com/sta/websocket-sharp/issues/305
Thanks.