Exemplo n.º 1
0
        static void listener_Accept(IAsyncResult ar)
        {
            object[]     state    = (object[])ar.AsyncState;
            Socket       listener = (Socket)state[0];
            TcpExChannel channel  = (TcpExChannel)state[1];
            Socket       client   = listener.EndAccept(ar);

            try
            {
                StartListening(Connection.CreateConnection(client, channel, channel.TcpKeepAliveEnabled, channel.TcpKeepAliveTime, channel.TcpKeepAliveInterval, channel.MaxRetries, channel.RetryDelay));
            }
            catch (DuplicateConnectionException)
            {
            }
            catch (IOException)
            {
                // Client socket is not responding
                //TODO: Add Tracing here!
            }
            catch (SerializationException)
            {
                // Client sends bad data
                //TODO: Add Tracing here!
            }
            // Wait for next Client request
            listener.BeginAccept(new AsyncCallback(listener_Accept), new object[] { listener, channel });
        }
Exemplo n.º 2
0
        static void listener_Accept(IAsyncResult ar)
        {
            object[]     state    = (object[])ar.AsyncState;
            Socket       listener = (Socket)state[0];
            TcpExChannel channel  = (TcpExChannel)state[1];
            Socket       client;

            try
            {
                client = listener.EndAccept(ar);

                // Wait for next Client request
                listener.BeginAccept(new AsyncCallback(listener_Accept), new object[] { listener, channel });
            }
            catch (ObjectDisposedException ex)
            {
                // the listener was closed
                Trace.WriteLine("TcpEx.Manager: the listener was closed. Got exception: " + ex.ToString());
                return;
            }

            try
            {
                StartListening(Connection.CreateConnection(client, channel, channel.TcpKeepAliveEnabled, channel.TcpKeepAliveTime, channel.TcpKeepAliveInterval, channel.MaxRetries, channel.RetryDelay));
            }
            catch (DuplicateConnectionException)
            {
            }
            catch (IOException ex)
            {
                // Client socket is not responding
                Trace.WriteLine("TcpEx.Manager: client socket is not responding. Got exception: " + ex.ToString());
            }
            catch (SerializationException ex)
            {
                // Client sends bad data
                Trace.WriteLine("TcpEx.Manager: client is sending bad data. Got exception: " + ex.ToString());
            }
            catch (Exception ex)
            {
                // Cannot cleanly connect to the remote party
                // it's probably not TcpEx channel that's trying to connect us
                Trace.WriteLine("TcpEx.Manager: cannot accept the incoming connection. Got exception: " + ex.ToString());
                return;
            }
        }