/// <summary> /// HandeleSessionClosed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandeleSessionClosed(Object sender, IoSessionEventArgs e) { Connected = false; _logger.Info(String.Format("SessionClosed {0}", e.Session.RemoteEndPoint)); _logger.Debug(String.Format("#1 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), Connected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); if (ConnectionStateChaneged != null) { ConnectionStateChaneged(Connected); } else { _logger.Error(String.Format("Call HandeleSessionOpened but ConnectionStateChaneged Event is null")); } Manager.Connector.ExceptionCaught -= HandleException; Manager.Connector.SessionOpened -= HandeleSessionOpened; Manager.Connector.SessionClosed -= HandeleSessionClosed; Manager.Connector.SessionIdle -= HandleIdle; Manager.Connector.MessageReceived -= HandleReceived; Manager.Connector.Dispose(); Manager = null; if (AutoConnections) { StartReconnectTimer(); } }
private void SessionClosed(object sender, IoSessionEventArgs e) { IPEndPoint remoreIP = (IPEndPoint)e.Session.RemoteEndPoint; Debug.Log(String.Format("disconnect from server {0} {1}", remoreIP.Address, remoreIP.Port)); connector.Dispose(); thread.Abort(); isConnected = false; }
private void OnSessionDestroyed(Object sender, IoSessionEventArgs e) { Semaphore pool = _connectionPool; if (pool != null) { pool.Release(); } }
private void OnSessionDestroyed(Object sender, IoSessionEventArgs e) { AsyncSocketSession s = e.Session as AsyncSocketSession; if (s != null && _readWritePool != null) { _readWritePool.Push(s.ReadBuffer); _readWritePool.Push(s.WriteBuffer); } }
private void OnSessionDestroyed(Object sender, IoSessionEventArgs e) { AsyncSocketSession s = e.Session as AsyncSocketSession; if (s != null) { // clear the buffer and reset its count to original capacity if changed s.ReadBuffer.Dispose(); s.WriteBuffer.Dispose(); } }
private void SessionClosed(object sender, IoSessionEventArgs e) { IPEndPoint remoreIP = (IPEndPoint)e.Session.RemoteEndPoint; Debug.Log(String.Format("client disconnect from {0} {1}", remoreIP.Address, remoreIP.Port)); ClientObject client = (ClientObject)e.Session.GetAttribute(SERVER_KEY); clients.Remove(client); e.Session.RemoveAttribute(SERVER_KEY); client.Dispose(); }
/// <summary> /// HandeleSessionClosed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandeleSessionClosed(Object sender, IoSessionEventArgs e) { Connected = false; _logger.Info(String.Format("SessionClosed {0}", e.Session.RemoteEndPoint)); _logger.Debug(String.Format("#1 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), Connected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); if (ConnectionStateChaneged != null) { ConnectionStateChaneged(Connected); } else { _logger.Error(String.Format("Call HandeleSessionOpened but ConnectionStateChaneged Event is null")); } }
private void OnSessionDestroyed(Object sender, IoSessionEventArgs e) { AsyncSocketSession s = e.Session as AsyncSocketSession; if (s != null && _readWritePool != null) { // clear the buffer and reset its count to original capacity if changed s.ReadBuffer.Clear(); s.ReadBuffer.SetBuffer(); _readWritePool.Push(s.ReadBuffer); s.WriteBuffer.Clear(); s.WriteBuffer.SetBuffer(); _readWritePool.Push(s.WriteBuffer); } }
private void SessionOpened(object sender, IoSessionEventArgs e) { IPEndPoint remoreIP = (IPEndPoint)e.Session.RemoteEndPoint; if (clients.Count >= maxConnect) { Debug.Log(String.Format("Reject client connecte from {0} {1}, reason Reason: connection to reach the upper limit.", remoreIP.Address, remoreIP.Port)); e.Session.Write(System.Text.Encoding.UTF8.GetBytes("Reject connect, Reason: connection to reach the upper limit.")); e.Session.CloseNow(); return; } Debug.Log(String.Format("client connected from {0} {1}", remoreIP.Address, remoreIP.Port)); ClientObject client = new ClientObject(e.Session); e.Session.SetAttribute(SERVER_KEY, client); clients.Add(client); }
/// <summary> /// HandeleSessionOpened /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandeleSessionOpened(Object sender, IoSessionEventArgs e) { Connected = true; lock (_lockObject) { if (MultipleConnections) { Sessions.Add(e.Session); _logger.Info(String.Format("MultipleConnections ON")); _logger.Info(String.Format("SessionOpened {0}", e.Session.RemoteEndPoint)); _logger.Debug(String.Format("#1 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), Connected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); if (ConnectionStateChaneged != null) { ConnectionStateChaneged(Connected); } else { _logger.Error(String.Format("Call HandeleSessionOpened but ConnectionStateChaneged Event is null")); } } else { if (Sessions.Count < 1) { Sessions.Add(e.Session); _logger.Info(String.Format("SessionOpened {0}", e.Session.RemoteEndPoint)); _logger.Debug(String.Format("#1 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), Connected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); if (ConnectionStateChaneged != null) { ConnectionStateChaneged(Connected); } else { _logger.Error(String.Format("Call HandeleSessionOpened but ConnectionStateChaneged Event is null")); } } else { _logger.Error(String.Format("We allow only one connection in this case")); e.Session.Close(true); } } } }
/// <summary> /// HandeleSessionClosed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandeleSessionClosed(Object sender, IoSessionEventArgs e) { Connected = false; lock (_lockObject) { if (MultipleConnections) { _logger.Info(String.Format("MultipleConnections ON")); _logger.Info(String.Format("SessionClosed {0}", e.Session.RemoteEndPoint)); _logger.Debug(String.Format("#1 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), Connected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); Sessions.Remove(e.Session); foreach (var s in Sessions) // check all remaning Sessions { if (s.Connected) { Connected = true; } } } else { Sessions.Remove(e.Session); _logger.Info(String.Format("SessionClosed {0}", e.Session.RemoteEndPoint)); _logger.Debug(String.Format("#1 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), Connected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); } if (ConnectionStateChaneged != null) { ConnectionStateChaneged(Connected); } else { _logger.Error(String.Format("Call HandeleSessionOpened but ConnectionStateChaneged Event is null")); } } }
private void Connector_SessionClosed(object sender, IoSessionEventArgs e) { State = ConnectingState.Disconnected; }
private void SessionOpened(object sender, IoSessionEventArgs e) { IPEndPoint remoreIP = (IPEndPoint)e.Session.RemoteEndPoint; Debug.Log(String.Format("connect to server {0} {1}", remoreIP.Address, remoreIP.Port)); }