# Catching network disconnection

**URL:** <https://forum.heroiclabs.com/t/catching-network-disconnection/1042>\
**Category:** Game Design\
**Created:** [October 11, 2020, 12:56pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042 "2020-10-11T12:56:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![oshribin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oshribin/32/349_2.png) [@oshribin](https://forum.heroiclabs.com/u/oshribin)\
**Post date:** [October 11, 2020, 12:56pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/1 "2020-10-11T12:56:30Z")

</div>

Is there a way to reduce the time it takes for the client to fail with network disconnection? or alternatively cancel the request?

I am trying to implement a way to overcome network disconnection. therefore I am recognizing when a request failed due to network issues and exposing a retry button. But it can take sometimes 60 seconds from the time I am disconnecting the network until the request is actually failed. (I can’t simply use a timer without canceling the requests, because if I will perform retry without canceling the request it might result in a duplicated requests)

---

<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:** [October 11, 2020, 4:18pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/2 "2020-10-11T16:18:27Z")

</div>

@oshribin Is this for network requests sent from game clients with one of the client SDKs? Which one do you use?

---

<div class="post-metadata">

**Author:** ![oshribin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oshribin/32/349_2.png) [@oshribin](https://forum.heroiclabs.com/u/oshribin)\
**Post date:** [October 11, 2020, 8:56pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/3 "2020-10-11T20:56:18Z")

</div>

Yes, I am using the unity sdk

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [October 12, 2020, 2:31pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/4 "2020-10-12T14:31:25Z")

</div>

@oshribin you can set the `Timeout` value on your `Client` object which defaults to fifteen seconds in the Unity SDK.

Since you’re noticing it taking longer than that I wonder if something else is at play. Are you wrapping your network calls in `try..catch` blocks to catch any network errors?

---

<div class="post-metadata">

**Author:** ![oshribin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oshribin/32/349_2.png) [@oshribin](https://forum.heroiclabs.com/u/oshribin)\
**Post date:** [October 12, 2020, 4:59pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/5 "2020-10-12T16:59:02Z")

</div>

Yes I am actually wrapping the underlying `client.RpcAsync` with more than one `try..catch` blocks before the final error is being thrown but I don’t see why it will increase the time it takes to catch the error from 15 seconds to 60 seconds.

tnx

---

<div class="post-metadata">

**Author:** ![oshribin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oshribin/32/349_2.png) [@oshribin](https://forum.heroiclabs.com/u/oshribin)\
**Post date:** [October 12, 2020, 8:37pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/6 "2020-10-12T20:37:03Z")

</div>

From what I can see `SendAsync` under `Nakama.HttpRequestAdapter` does not make any use of the timeout variable

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [October 12, 2020, 10:30pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/7 "2020-10-12T22:30:36Z")

</div>

@oshribin the `UnityWebRequest` adapter in the Unity client does make use of the timeout variable: [https://github.com/heroiclabs/nakama-unity/blob/master/Packages/Nakama/Runtime/UnityWebRequestAdapter.cs#L109](https://github.com/heroiclabs/nakama-unity/blob/master/Packages/Nakama/Runtime/UnityWebRequestAdapter.cs#L109)

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [October 12, 2020, 10:33pm UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/8 "2020-10-12T22:33:18Z")

</div>

Could you also share the error message you receive on network disconnection? Are you testing it using some network throttler or turning off the WIFI?

---

<div class="post-metadata">

**Author:** ![oshribin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oshribin/32/349_2.png) [@oshribin](https://forum.heroiclabs.com/u/oshribin)\
**Post date:** [October 13, 2020, 6:53am UTC](https://forum.heroiclabs.com/t/catching-network-disconnection/1042/9 "2020-10-13T06:53:46Z")

</div>

I will try the unityWebRequestAdapter.

I am testing both, I don’t get a disconnection with the throttler as it managed eventually to process the request. unless I am setting the throttler to 100% packet loss. then like with turning off the wifi. it takes about 60 seconds until I am getting the following excpetion:

`nakama_call_failed: System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Network is unreachable) ---> System.Net.Sockets.SocketException: Network is unreachable at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in <735c83e43c004ee998f77c68cf8035da>:0 at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in <735c83e43c004ee998f77c68cf8035da>:0 `
