How to add a reconnect method :question
bomanden opened this issue · comments
How to add a reconnect method
if the server is reset or other error occurs ?
got it working by adding a method to UnityWebsocket.cs
public bool IsAlive() {
return (_ws == null) ? false : _ws.IsOpen();
}
and having a Coroutine UnityWebSocketScript.cs running from start checking every 15 secs
private IEnumerator ReconnectWS() {
while (true) {
yield return new WaitForSeconds(15);
if (!IsAlive()) {
Debug.Log("[UnityWebSocketScript] try reconnecting");
Connect();
}
}
}
Good enough ? or any recommendations