Socket disconnected due to Internet connection In Unity client

How Client will get notify in real time? Is there anyway or callback function as soon as socket disconnects to the server due to internet connection event should trigger in real time. Now in unity client its taking around 30 secs to throw an error. As soon as internet goes down we want to end the game. Help is much appreciated.

@kailas The socket does fire a callback event handler called Closed as soon as the disconnect is detected. You can adjust the speed that disconnects are observed by changing how frequently heartbeats are sent by the client over the socket.

var client = new Client("scheme", "host", port, "key"); // set correct values
var keepAliveIntervalSec = 5;
var socket = Socket.From(client, new WebSocketAdapter(keepAliveIntervalSec));

Note that more heartbeats means more data over the network. You should also keep in mind that the exact speed a disconnect is observed over the network is dependent on the net stack of the operating system the Unity project is running on. Don’t expect it to be the same on Windows, macOS, Linux, Android, iOS, etc, etc.