Beispiel #1
0
 public void CloseAcceptor(MessageChannelAcceptor acceptor)
 {
     acceptor.Close();
     if (channelAcceptorList.Contains(acceptor))
     {
         channelAcceptorList.Remove(acceptor);
     }
 }
Beispiel #2
0
        // Accept one client connection asynchronously.
        public void DoBeginAcceptSocket(MessageChannelAcceptor listener)
        {
            // Start to listen for connections from a client.
            if (log.IsDebugEnabled)
            {
                log.Debug("Waiting for a connection...");
            }

            // Accept the connection.
            // BeginAcceptSocket() creates the accepted socket.
            listener.ServerSocket.BeginAcceptSocket(new AsyncCallback(DoAcceptSocketCallback), listener);
        }
Beispiel #3
0
        // Process the client connection.
        public void DoAcceptSocketCallback(IAsyncResult ar)
        {
            // Get the listener that handles the client request.
            MessageChannelAcceptor listener = (MessageChannelAcceptor)ar.AsyncState;

            if (listener.IsClosed)
            {
                return;
            }

            // End the operation and display the received data on the
            //console.
            Socket clientSocket = listener.ServerSocket.EndAcceptSocket(ar);

            // Process the connection here. (Add the client to a
            // server table, read data, etc.)
            if (log.IsDebugEnabled)
            {
                log.Debug("Client connected to " + clientSocket.LocalEndPoint + " from " + clientSocket.RemoteEndPoint);
                log.Debug("Timeouts in mls: Receive " + clientSocket.ReceiveTimeout + ", Send " + clientSocket.SendTimeout);
            }
            // The socket will linger for 10 seconds after Socket.Close is called.
            LingerOption lingerOption = new LingerOption(true, 10);

            clientSocket.LingerState = lingerOption;

            TCPMessageChannel channel = new TCPMessageChannel(clientSocket);

            channel.ChannelDataAvailable += new OnDataAvailable(ProcessChannelDataAvailable);
            AddChannel(channel);

            // Accept a new connection
            if (keepGoing)
            {
                DoBeginAcceptSocket(listener);
            }
        }