public AsyncTcpSocketSession GetSession(string sessionKey) { AsyncTcpSocketSession session = null; _sessions.TryGetValue(sessionKey, out session); return(session); }
private async Task Process(TcpClient acceptedTcpClient) { var session = new AsyncTcpSocketSession(acceptedTcpClient, _configuration, _configuration.BufferManager, _dispatcher, this); if (_sessions.TryAdd(session.SessionKey, session)) { _log.Debug("New session [{0}].", session); try { await session.Start(); } catch (TimeoutException ex) { _log.Error(ex.Message, ex); } finally { AsyncTcpSocketSession throwAway; if (_sessions.TryRemove(session.SessionKey, out throwAway)) { _log.Debug("Close session [{0}].", throwAway); } } } }
public async Task OnSessionClosed(AsyncTcpSocketSession session) { if (_onSessionClosed != null) { await _onSessionClosed(session); } }
public async Task OnSessionDataReceived(AsyncTcpSocketSession session, byte[] data, int offset, int count) { if (_onSessionDataReceived != null) { await _onSessionDataReceived(session, data, offset, count); } }
public async Task CloseSession(string sessionKey) { AsyncTcpSocketSession session = null; if (_sessions.TryGetValue(sessionKey, out session)) { await session.Close(); // parent server close session by session-key } }
public async Task SendToAsync(AsyncTcpSocketSession session, byte[] data, int offset, int count) { AsyncTcpSocketSession sessionFound; if (_sessions.TryGetValue(session.SessionKey, out sessionFound)) { await sessionFound.SendAsync(data, offset, count); } else { _log.Warning("Cannot find session [{0}].", session); } }
public async Task SendToAsync(AsyncTcpSocketSession session, byte[] data) { await SendToAsync(session, data, 0, data.Length); }