예제 #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);
 }