Beispiel #1
0
 public async Task OnSessionClosed(AsyncTcpSocketSession session)
 {
     if (_onSessionClosed != null)
     {
         await _onSessionClosed(session);
     }
 }
Beispiel #2
0
 public async Task OnSessionDataReceived(AsyncTcpSocketSession session, byte[] data, int offset, int count)
 {
     if (_onSessionDataReceived != null)
     {
         await _onSessionDataReceived(session, data, offset, count);
     }
 }
Beispiel #3
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.WarnFormat("Cannot find session [{0}].", session);
            }
        }
Beispiel #4
0
        private async Task Process(TcpClient acceptedTcpClient)
        {
            var session = new AsyncTcpSocketSession(acceptedTcpClient, _configuration, _bufferManager, _dispatcher, this);

            if (_sessions.TryAdd(session.SessionKey, session))
            {
                try
                {
                    await session.Start();
                }
                catch (TimeoutException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    AsyncTcpSocketSession throwAway;
                    if (_sessions.TryRemove(session.SessionKey, out throwAway))
                    {
                        //_log.DebugFormat("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);
 }
Beispiel #7
0
 public async Task OnSessionClosed(AsyncTcpSocketSession session)
 {
    // Console.WriteLine(string.Format("TCP session {0} has disconnected.", session));
     await Task.CompletedTask;
 }
Beispiel #8
0
        public async Task OnSessionDataReceived(AsyncTcpSocketSession session, byte[] data, int offset, int count)
        {
           

            var text = Encoding.UTF8.GetString(data, offset, count);
            Console.Write(string.Format("Client : {0} --> ", session.RemoteEndPoint));
            Console.WriteLine(string.Format("{0}", text));
            if (Rev != null)
            {
                
                Rev(null, new StrEventArgs() {  Text=text});
            }
            await session.SendAsync(Encoding.UTF8.GetBytes(text));

           
        }
Beispiel #9
0
 public async Task OnSessionStarted(AsyncTcpSocketSession session)
 {
    // Console.WriteLine(string.Format("TCP session {0} has connected {1}.", session.RemoteEndPoint, session));
     await Task.CompletedTask;
 }
 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.WarnFormat("Cannot find session [{0}].", session);
     }
 }
 public async Task SendToAsync(AsyncTcpSocketSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }
        private async Task Process(TcpClient acceptedTcpClient)
        {
            var session = new AsyncTcpSocketSession(acceptedTcpClient, _configuration, _bufferManager, _dispatcher, this);

            if (_sessions.TryAdd(session.SessionKey, session))
            {
               
                try
                {
                    await session.Start();
                }
                catch (TimeoutException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    AsyncTcpSocketSession throwAway;
                    if (_sessions.TryRemove(session.SessionKey, out throwAway))
                    {
                        //_log.DebugFormat("Close session [{0}].", throwAway);
                    }
                }
            }
        }
Beispiel #13
0
 public async Task SendToAsync(AsyncTcpSocketSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }