# Socket disconnected due to Internet connection In Unity client

**URL:** <https://forum.heroiclabs.com/t/socket-disconnected-due-to-internet-connection-in-unity-client/631>\
**Category:** Game Design\
**Tags:** getting-started, server-framework\
**Created:** [April 12, 2020, 8:37pm UTC](https://forum.heroiclabs.com/t/socket-disconnected-due-to-internet-connection-in-unity-client/631 "2020-04-12T20:37:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kailas](https://avatars.discourse-cdn.com/v4/letter/k/bbce88/32.png) [@kailas](https://forum.heroiclabs.com/u/kailas)\
**Post date:** [April 12, 2020, 8:37pm UTC](https://forum.heroiclabs.com/t/socket-disconnected-due-to-internet-connection-in-unity-client/631/1 "2020-04-12T20:37:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [April 13, 2020, 5:12pm UTC](https://forum.heroiclabs.com/t/socket-disconnected-due-to-internet-connection-in-unity-client/631/2 "2020-04-13T17:12:24Z")

</div>

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

```auto
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.
