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.Exception($"New session [{session}]");
                try
                {
                    await session.Start();
                }
                catch (TimeoutException ex)
                {
                    _log.Exception(ex);
                }
                finally
                {
                    AsyncTcpSocketSession throwAway;
                    if (_sessions.TryRemove(session.SessionKey, out throwAway))
                    {
                        _log.Exception($"Close session [{throwAway}]");
                    }
                }
            }
        }
 public async Task OnSessionStarted(AsyncTcpSocketSession session)
 {
     if (_onSessionStarted != null)
     {
         await _onSessionStarted(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.Exception($"Cannot find session [{session}].");
            }
        }
 public async Task SendToAsync(AsyncTcpSocketSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }