iOS socket disconnected event

Hi Everyone!

We are facing a weird issue in iOS. We subscribed to the _socket.Closed event to detect socket disconnect issue and try to reconnect using a new socket.

While trying this on an android phone, we are getting the event called immediately. But for iOS, it’s taking time to fire the event when I turn off the wifi of an iOS device, like 30/40 seconds.

Is it expected?

_socket.Closed += InternetConnectivity.OnSocketClosed;
  1. Nakama: Nakama: 3.1.2
  2. Server Framework Runtime language: Lua
  3. Unity SDK: 2.8.1

Hi Foysal,

Welcome to the Heroic Labs community and thank you for sharing that you are working with Nakama.

Socket timeouts are dependant on the client’s underlying socket usage so they may differ between platforms and versions.

You can set the default timeout in Nakama for Unity in a couple of ways:

When connecting a socket you can specify the timeout. You will need to create the socket first.

Or passing an existing ISocketAdaptor instance with timeout configured to the Socket.From method.

Additionally, you can configure the server socket ping and pong timeout.

With a combination of configuring the server and client you should be able to detect timeouts closer to when they occur. It will unfortunately never be accurate to the millisecond as timeout events are always reliant on underlying ping/pong messages and reasonable allowances for hiccups in the connection.

Kind regards,
Sean