コード例 #1
0
        private void StartNewTCPConnection(Uri connection)
        {
            ConnectionInfo info = new ConnectionInfo();

            info.Addr = connection.DnsSafeHost;
            info.Port = connection.Port;

            System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(info.Addr);
            System.Net.IPAddress   ipAddress = System.Net.Dns.GetHostEntry(hostEntry.HostName).AddressList[0];
            IPEndPoint             endpoint  = new IPEndPoint(ipAddress, info.Port);

            foreach (MessageChannelAcceptor acceptor in channelAcceptorList)
            {
                if (!acceptor.IsClosed && acceptor.LocalEndPoint != null && acceptor.LocalEndPoint.Equals(endpoint))
                {
                    //We are trying to connect to our own acceptor!
                    return;
                }
            }

            TCPMessageChannel channel = new TCPMessageChannel(info);

            if (log.IsDebugEnabled)
            {
                log.Debug("Connected from " + channel.InternalSocket.LocalEndPoint +
                          " to " + channel.InternalSocket.RemoteEndPoint);
                log.Debug("Timeouts in mls: Receive " + channel.InternalSocket.ReceiveTimeout +
                          ", Send " + channel.InternalSocket.SendTimeout);
            }

            AddChannel(channel);
        }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: ChannelsManager.cs プロジェクト: superliujian/Sxta
        private void StartNewTCPConnection(Uri connection)
        {
            ConnectionInfo info = new ConnectionInfo();
            info.Addr = connection.DnsSafeHost;
            info.Port = connection.Port;

            System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(info.Addr);
            System.Net.IPAddress ipAddress = System.Net.Dns.GetHostEntry(hostEntry.HostName).AddressList[0];
            IPEndPoint endpoint = new IPEndPoint(ipAddress, info.Port);
            foreach (MessageChannelAcceptor acceptor in channelAcceptorList)
            {
                if (!acceptor.IsClosed && acceptor.LocalEndPoint != null && acceptor.LocalEndPoint.Equals(endpoint))
                {
                    //We are trying to connect to our own acceptor!
                    return;
                }
            }

            TCPMessageChannel channel = new TCPMessageChannel(info);

            if (log.IsDebugEnabled)
            {
                log.Debug("Connected from " + channel.InternalSocket.LocalEndPoint +
                          " to " + channel.InternalSocket.RemoteEndPoint);
                log.Debug("Timeouts in mls: Receive " + channel.InternalSocket.ReceiveTimeout +
                          ", Send " + channel.InternalSocket.SendTimeout);
            }

            AddChannel(channel);
        }
コード例 #4
0
ファイル: ChannelsManager.cs プロジェクト: superliujian/Sxta
        // 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);
        }