Ejemplo n.º 1
0
        public AsyncTcpSocketSession GetSession(string sessionKey)
        {
            AsyncTcpSocketSession session = null;

            _sessions.TryGetValue(sessionKey, out session);
            return(session);
        }
Ejemplo n.º 2
0
        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);
     }
 }
Ejemplo n.º 5
0
        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
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 public async Task SendToAsync(AsyncTcpSocketSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }