Пример #1
0
        internal NPHandler(NPServerClient client)
        {
            _messages = new Queue <NPMessage>();
            _client   = client;

            LastCI = DateTime.UtcNow;
        }
Пример #2
0
        void _acceptEventArgs_Completed(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                if (e.SocketError == SocketError.Success)
                {
                    var clientSocket = e.AcceptSocket;
                    var client       = new NPServerClient();
                    client.readEventArgs.AcceptSocket = clientSocket;
                    client.readEventArgs.Completed   += new EventHandler <SocketAsyncEventArgs>(client_Completed);
                    client.readEventArgs.UserToken    = client;
                    client.readEventArgs.SetBuffer(client.receiveBuffer, 0, client.receiveBuffer.Length);
                    client.writeEventArgs.AcceptSocket = clientSocket;
                    client.writeEventArgs.Completed   += new EventHandler <SocketAsyncEventArgs>(client_Completed);
                    client.writeEventArgs.UserToken    = client;
                    client.writeEventArgs.SetBuffer(client.sendBuffer, 0, client.sendBuffer.Length);
                    client.socket  = clientSocket;
                    client.handler = new NPHandler(client);

                    lock (_clients)
                    {
                        _clients.Add(client);
                    }

                    //DoReceive(client.readEventArgs);
                    if (!client.socket.ReceiveAsync(client.readEventArgs))
                    {
                        HandleReceive(client.readEventArgs);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }

            DoAccept(e);
        }
Пример #3
0
 internal NPHandler(NPServerClient client)
 {
     _messages = new Queue <NPMessage>();
     _client   = client;
 }
Пример #4
0
 internal static void Close(NPServerClient client)
 {
     _instance.CloseSocket(client.readEventArgs);
 }