void Process()
    {
        while (ContinueProcess)
        {
            ClientHandler client = null;

            lock (ConnectionPool.SyncRoot)
            {
                if (ConnectionPool.Count > 0)
                {
                    client = ConnectionPool.Dequeue();
                }
            }

            if (client != null)
            {
                client.Process();

                if (client.Alive)
                {
                    ConnectionPool.Enqueue(client);
                }
            }

            Thread.Sleep(1);
        }
    }
Example #2
0
    private void Process()
    {
        while (ContinueProcess)
        {
            ClientHandler client = null;
            lock (ConnectionPool.SyncRoot)
            {
                if (ConnectionPool.Count > 0)
                {
                    client = ConnectionPool.Dequeue();
                }
            }
            if (client != null)
            {
                client.Process(); // Provoke client
                // if client still connect, schedufor later processingle it
                if (client.Alive)
                {
                    ConnectionPool.Enqueue(client);
                }
            }

            Thread.Sleep(100);
        }
    }
Example #3
0
    public static void StartListening(BizDomain equityDomain)
    {
        ManualResetEvent waitForConnect = new ManualResetEvent(false);
        ClientService    ClientTask;
        IPAddress        localAddr = IPAddress.Parse("127.0.0.1");

        // Client Connections Pool
        ClientConnectionPool ConnectionPool = new ClientConnectionPool();

        // Client Task to handle client requests
        ClientTask = new ClientService(ConnectionPool);

        ClientTask.Start();

        TcpListener listener = new TcpListener(localAddr, portNum);

        try
        {
            listener.Start();

            int TestingCycle = 3; // Number of testing cycles
            int ClientNbr    = 0;

            // Start listening for connections.
            Console.WriteLine("Waiting for a connection...");
            while (TestingCycle > 0 && EquityMatchingEngine.OMEHost.running == true)
            {
                TcpClient handler = listener.AcceptTcpClient();

                if (handler != null)
                {
                    Console.WriteLine("Client#{0} accepted!", ++ClientNbr);

                    // An incoming connection needs to be processed.
                    ConnectionPool.Enqueue(new ClientHandler(handler, equityDomain));

                    //--TestingCycle;
                }
                else
                {
                    break;
                }

                waitForConnect.WaitOne(100); //
            }
            waitForConnect.WaitOne(1000);
            listener.Stop();
            Console.WriteLine("Order Listener Stoped");
            // Stop client requests handling
            ClientTask.Stop();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }

        //Console.WriteLine("\nHit enter to continue...");
        //Console.Read();
    }
Example #4
0
    public static void StartListening()
    {
        ClientService ClientTask  ;

        // Client Connections Pool
        ClientConnectionPool ConnectionPool = new ClientConnectionPool()  ;

        // Client Task to handle client requests
        ClientTask = new ClientService(ConnectionPool) ;

        ClientTask.Start() ;

        TcpListener listener = new TcpListener(portNum);
        try
        {
            listener.Start();

            int TestingCycle = 3 ; // Number of testing cycles
            int ClientNbr = 0 ;

            // Start listening for connections.
            Console.WriteLine("Waiting for a connection...");
            while ( TestingCycle > 0 )
            {

                TcpClient handler = listener.AcceptTcpClient();

                if (  handler != null)
                {
                    Console.WriteLine("Client#{0} accepted!", ++ClientNbr) ;

                    // An incoming connection needs to be processed.
                    ConnectionPool.Enqueue( new ClientHandler(handler) ) ;

                    //--TestingCycle ;
                }
                else
                    break;
            }
            listener.Stop();

            // Stop client requests handling
            ClientTask.Stop() ;

        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }

        Console.WriteLine("\nHit enter to continue...");
        Console.Read();
    }
Example #5
0
    public static void StartListening()
    {
        ClientService ClientTask;

        // Client Connections Pool
        ClientConnectionPool ConnectionPool = new ClientConnectionPool();

        // Client Task to handle client requests
        ClientTask = new ClientService(ConnectionPool);

        ClientTask.Start();

        TcpListener listener = new TcpListener(portNum);

        try {
            listener.Start();

            int TestingCycle = 3;    // Number of testing cycles
            int ClientNbr    = 0;

            // Start listening for connections.
            Console.WriteLine("Waiting for a connection...");
            while (TestingCycle > 0)
            {
                TcpClient handler = listener.AcceptTcpClient();

                if (handler != null)
                {
                    Console.WriteLine("Client#{0} accepted!", ++ClientNbr);

                    // An incoming connection needs to be processed.
                    ConnectionPool.Enqueue(new ClientHandler(handler));

                    --TestingCycle;
                }
                else
                {
                    break;
                }
            }
            listener.Stop();

            // Stop client requests handling
            ClientTask.Stop();
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        }

        Console.WriteLine("\nHit enter to continue...");
        Console.Read();
    }
    public static void StartListening()
    {
        var ConnectionPool = new ClientConnectionPool();
        var ClientTask     = new ClientService(ConnectionPool);

        ClientTask.Start();

        var listener = new TcpListener(portNum);

        try
        {
            listener.Start();

            int ClientNbr = 0;

            // Start listening for connections.
            Console.WriteLine("Waiting for a connection...");

            while (true)
            {
                TcpClient handler = listener.AcceptTcpClient();

                if (handler != null)
                {
                    Console.WriteLine("Client#{0} accepted!", ++ClientNbr);
                    ConnectionPool.Enqueue(new ClientHandler(handler));
                }

                Thread.Sleep(1);
            }

            //listener.Stop();
            //ClientTask.Stop();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
    }
Example #7
0
        private void AcceptCallback(IAsyncResult ar)
        {
            try
            {
                var       server = (TcpListener)ar.AsyncState;
                TcpClient tcp    = server.EndAcceptTcpClient(ar);
                tcp.ReceiveBufferSize = Config.CHUNK_SIZE;
                tcp.SendTimeout       = Config.SEND_TIMEOUT;
                tcp.ReceiveTimeout    = tcp.SendTimeout;
                tcp.SendBufferSize    = Config.CHUNK_SIZE;

                server.BeginAcceptTcpClient(AcceptCallback, server);

                if (tcp != null)
                {
                    // An incoming connection needs to be processed.
                    var ch = new ClientHandler(tcp, _processPayload);
                    _ConnectionPool.Enqueue(ch);
                }
            }
            catch
            {
            }
        }