public void ConnectWSReliable() { mustConnectBy = DateTime.Now.AddMilliseconds(GameSparksRT.ComputeSleepPeriod(connectionAttempts) + GameSparksRT.HandshakeOffset * 10); reliableWSConnection = new ReliableWSConnection(hostName, TcpPort, this); }
private void CheckConnection() { try { if (DateTime.Now > mustConnectBy) { if (ConnectState == GameSparksRT.ConnectState.Disconnected) { Log("IRTSession", GameSparksRT.LogLevel.INFO, "Disconnected, trying to connect"); ConnectState = GameSparksRT.ConnectState.Connecting; #if !__WINDOWS__ if (useOnlyWebSockets) { ConnectWSReliable(); } else #endif { ConnectReliable(); } connectionAttempts++; } else if (ConnectState == GameSparksRT.ConnectState.Connecting) { ConnectState = GameSparksRT.ConnectState.Disconnected; Log("IRTSession", GameSparksRT.LogLevel.INFO, "Not connected in time, retrying"); #if !__WINDOWS__ if (useOnlyWebSockets) { if (reliableWSConnection != null) { reliableWSConnection.StopInternal(); reliableWSConnection = null; } } else #endif { if (reliableConnection != null) { reliableConnection.StopInternal(); reliableConnection = null; } if (fastConnection != null) { fastConnection.StopInternal(); fastConnection = null; } } } } #if __WINDOWS__ #else } catch (ThreadAbortException e) { Log("IRTSession", GameSparksRT.LogLevel.INFO, e.StackTrace); return; #endif } catch (Exception e) { //General exception, ignore it System.Diagnostics.Debug.WriteLine(e); Log("IRTSession", GameSparksRT.LogLevel.ERROR, e.StackTrace); } }