protected override void Reconnect(Connection.Base connection) { if (connection != null) { CloseMonitor(connection.Remote); } }
protected void Close(Connection.Base connection) { if (connection != null) { if (connection is Connection.Tcp) { lock (initializedConnections) { initializedConnections.Remove(connection as Connection.Tcp); } } if (connection.Channel != ushort.MaxValue) { lock (openedChannels) { Connection.Base[] connections; if (openedChannels.TryGetValue(connection.Remote, out connections)) { connections[connection.Channel] = null; } openedChannels.Remove(connection.Remote); } } connection.Close(); } }
protected override void Reconnect(Connection.Base connection) { if (state == State.RUNNING && connection != null && connection.AutoReconnect) { if (connection != null && CloseMonitor(connection.Remote)) { Connect(); } else { Type type = connection.GetType(); if (typeof(Connection.Tcp).IsAssignableFrom(type)) { ConnectTcp(connection.Parameters); } else if (typeof(Connection.Udp).IsAssignableFrom(type)) { if (monitors.TryGetValue(connection.Remote, out Connection.Tcp monitor)) { ConnectUdp(monitor, connection.Parameters); } else { Debug.LogErrorFormat("No monitor channel with guid '{0}' to reconnect UDP channel {1}", connection.Remote, connection.Channel); } } } } }
protected void DisconnectionHandler(Connection.Base connection) { Close(connection); if (state == State.RUNNING) { Reconnect(connection); } }
protected abstract void Reconnect(Connection.Base connection);