public TcpSocketSession GetSession(string sessionKey) { TcpSocketSession session = null; _sessions.TryGetValue(sessionKey, out session); return(session); }
public void BeginSendTo(TcpSocketSession session, byte[] data, int offset, int count) { GuardRunning(); if (session == null) { throw new ArgumentNullException("session"); } if (data == null) { throw new ArgumentNullException("data"); } TcpSocketSession writeSession = null; if (_sessions.TryGetValue(session.SessionKey, out writeSession)) { session.BeginSend(data, offset, count); } else { _log.Exception(string.Format("Cannot find session [{0}].", session)); } }
public TcpClientDataReceivedEventArgs(TcpSocketSession session, byte[] data, int dataOffset, int dataLength) { Session = session; Data = data; DataOffset = dataOffset; DataLength = dataLength; }
public IAsyncResult BeginSendTo(TcpSocketSession session, byte[] data, int offset, int count, AsyncCallback callback, object state) { GuardRunning(); if (session == null) { throw new ArgumentNullException("session"); } if (data == null) { throw new ArgumentNullException("data"); } TcpSocketSession writeSession = null; if (_sessions.TryGetValue(session.SessionKey, out writeSession)) { return(session.BeginSend(data, offset, count, callback, state)); } else { _log.Exception(string.Format("Cannot find session [{0}].", session)); } return(null); }
private void CloseSession(TcpSocketSession session) { TcpSocketSession sessionToBeThrowAway; _sessions.TryRemove(session.SessionKey, out sessionToBeThrowAway); session?.Close();// parent server close session }
public TcpClientConnectedEventArgs(TcpSocketSession session) { if (session == null) { throw new ArgumentNullException("session"); } Session = session; }
public void CloseSession(string sessionKey) { TcpSocketSession session = null; if (_sessions.TryGetValue(sessionKey, out session)) { session.Close(); // parent server close session by session-key } }
internal void RaiseClientConnected(TcpSocketSession session) { try { ClientConnected?.Invoke(this, new TcpClientConnectedEventArgs(session)); } catch (Exception ex) { HandleUserSideError(session, ex); } }
internal void RaiseClientDataReceived(TcpSocketSession session, byte[] data, int dataOffset, int dataLength) { try { ClientDataReceived?.Invoke(this, new TcpClientDataReceivedEventArgs(session, data, dataOffset, dataLength)); } catch (Exception ex) { HandleUserSideError(session, ex); } }
private void HandleTcpClientAccepted(IAsyncResult ar) { if (!_isListening) { return; } try { TcpListener listener = (TcpListener)ar.AsyncState; TcpClient tcpClient = listener.EndAcceptTcpClient(ar); if (!tcpClient.Connected) { return; } var session = new TcpSocketSession(tcpClient, _configuration, _configuration.BufferManager, this); bool isSessionStarted = false; try { _sessions.AddOrUpdate(session.SessionKey, session, (n, o) => o); session.Start(); isSessionStarted = true; } catch (Exception ex) { _log.Exception(ex); } if (isSessionStarted) { ContinueAcceptSession(listener); } else { CloseSession(session); //session was not started } } catch (Exception ex) { if (!ShouldThrow(ex)) { _log.Exception(ex); } else { throw; } } }
internal void RaiseClientDisconnected(TcpSocketSession session) { try { ClientDisconnected?.Invoke(this, new TcpClientDisconnectedEventArgs(session)); } catch (Exception ex) { HandleUserSideError(session, ex); } finally { TcpSocketSession sessionToBeThrowAway; _sessions.TryRemove(session.SessionKey, out sessionToBeThrowAway); } }
public void EndSendTo(TcpSocketSession session, IAsyncResult asyncResult) { GuardRunning(); if (session == null) { throw new ArgumentNullException("session"); } TcpSocketSession writeSession = null; if (_sessions.TryGetValue(session.SessionKey, out writeSession)) { session.EndSend(asyncResult); } }
public void EndSendTo(string sessionKey, IAsyncResult asyncResult) { GuardRunning(); if (string.IsNullOrEmpty(sessionKey)) { throw new ArgumentNullException("sessionKey"); } TcpSocketSession session = null; if (_sessions.TryGetValue(sessionKey, out session)) { session.EndSend(asyncResult); } }
public IAsyncResult BeginSendTo(TcpSocketSession session, byte[] data, AsyncCallback callback, object state) { GuardRunning(); if (session == null) { throw new ArgumentNullException("session"); } if (data == null) { throw new ArgumentNullException("data"); } return(BeginSendTo(session, data, 0, data.Length, callback, state)); }
public void BeginSendTo(TcpSocketSession session, byte[] data) { GuardRunning(); if (session == null) { throw new ArgumentNullException("session"); } if (data == null) { throw new ArgumentNullException("data"); } BeginSendTo(session, data, 0, data.Length); }
private void HandleUserSideError(TcpSocketSession session, Exception ex) { _log.Exception(string.Format("Session [{0}] error occurred in user side [{1}].", session, ex.Message)); }
public TcpClientDataReceivedEventArgs(TcpSocketSession session, byte[] data) : this(session, data, 0, data.Length) { }