Code Monkey home page Code Monkey logo

Comments (3)

mofirouz avatar mofirouz commented on May 28, 2024

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:

  1. OnSuccess / OnError callbacks that are passed into the Send() method.
  2. OnDisconnect / Global OnError.

OnSuccess / OnError callbacks

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.

OnDisconnect / Global OnError.

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:

  • On Unity Editor, neither OnDisconnect nor OnError are invoked.
  • On Android, OnDisconnect is invoked immediately after disconnecting from the network. OnError is also called in this situation.
  • On iOS, OnDisconnect is invoked after a couple of seconds but the OnError is not invoked.

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.

from nakama-unity.

chuidifly avatar chuidifly commented on May 28, 2024

@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?

from nakama-unity.

novabyte avatar novabyte commented on May 28, 2024

@chuidifly The SDK was redesigned since this issue was created. It would be good to discuss your questions on the forums.

from nakama-unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.