Пример #1
0
        private void AcceptCallback(IAsyncResult result)
        {
            try
            {
                var socket     = Listener.EndAccept(result);             // Finish accepting the incoming client.
                var connection = new Client(this, socket);               // Add the new connection to the dictionary.

                lock (ConnectionLock) Connections[socket] = connection;  // add the client to list.

                OnClientConnection(new ClientEventArgs(connection));     // Raise the ClientConnected event.

                connection.BeginReceive(ReceiveCallback, connection);    // Begin receiving on the new client connection.
                Listener.BeginAccept(AcceptCallback, null);              // Continue receiving other incoming clients asynchronously.
            }
            catch (Exception e)
            {
                Logger.DebugException(e, "AcceptCallback");
            }
        }
Пример #2
0
        private void AcceptCallback(IAsyncResult result)
        {
            try
            {
                var socket = Listener.EndAccept(result); // Finish accepting the incoming client.
                var connection = new Client(this, socket); // Add the new connection to the dictionary.

                lock (ConnectionLock) Connections[socket] = connection; // add the client to list.

                OnClientConnection(new ClientEventArgs(connection)); // Raise the ClientConnected event.

                connection.BeginReceive(ReceiveCallback, connection); // Begin receiving on the new client connection.
                Listener.BeginAccept(AcceptCallback, null); // Continue receiving other incoming clients asynchronously.
            }
            catch (Exception e)
            {
                Logger.DebugException(e, "AcceptCallback");
            }
        }