Ejemplo n.º 1
0
        void _acceptEventArgs_Completed(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                if (e.SocketError == SocketError.Success)
                {
                    var clientSocket = e.AcceptSocket;
                    var client       = new TCPClient();
                    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.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
                    client.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.OutOfBandInline, true);
                    client.router = new DWRouter();

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

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

            DoAccept(e);
        }
Ejemplo n.º 2
0
 internal static void Close(TCPClient client)
 {
     _instance.CloseSocket(client.readEventArgs);
 }