Esempio n. 1
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();
    }
Esempio n. 2
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();
    }
Esempio n. 3
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();
    }
Esempio n. 4
0
        public GatewayClientFactory(ILoggerFactory loggerFactory,
                                    IMessageCenter messageCenter,
                                    IPlacement placement,
                                    ClientConnectionPool clientPool
                                    )
        {
            this.logger               = loggerFactory.CreateLogger("GatewayClient");
            this.messageCenter        = messageCenter;
            this.placement            = placement;
            this.clientConnectionPool = clientPool;

            this.placement.RegisterServerChangedEvent(this.OnAddServer, this.OnRemoveServer, this.OnOfflineServer);
            this.placement.OnException(this.OnPDKeepAliveException);
        }
Esempio n. 5
0
 public bool SendMessageToServer(long serverID, object message)
 {
     if (this.clientConnectionPool == null)
     {
         this.clientConnectionPool = this.serviceProvider.GetRequiredService <ClientConnectionPool>();
     }
     if (this.clientConnectionPool != null)
     {
         var channel = this.clientConnectionPool.GetChannelByServerID(serverID);
         if (channel != null)
         {
             this.SendMessage(new OutboundMessage(channel, message));
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
        /// <summary>
        /// Constructs a new brain object.
        /// </summary>
        /// <param name="visionPreview">A capture element that is placed on a canvas used for capturing what Robbie sees.</param>
        /// <param name="previewCanvas">A canvas element used for rendering the image preview showing what Robbie sees.</param>
        /// <param name="audioPlaybackElement">A media element that is placed on a canvas used for speaking.</param>
        public Brain(CaptureElement visionPreview, Canvas previewCanvas, MediaElement audioPlaybackElement)
        {
            utterancePrediction = new UtterancePrediction();

            ears  = new Ears();
            voice = new Voice(audioPlaybackElement);
            eyes  = new Eyes(visionPreview, previewCanvas);

            pool = new ClientConnectionPool();

            currentIdentityPersonId = AnonymousPersonId;

            // define the event handlers for handling the different events occuring from all the senses
            ears.SpeechRecognized += Ears_SpeechRecognized;
            ears.EarsStateChanged += Ears_EarsStateChanged;
            voice.FinishedPlaybackEventHandler += Voice_FinishedPlayback;
            eyes.NewActivePersonEvent          += Eyes_NewActivePersonEvent;

            // always start in a sleeping state (not actively listening)
            sleeping = true;
        }
Esempio n. 7
0
        public GatewayMessageHandler(IServiceProvider serviceProvider,
                                     IMessageCenter messageCenter,
                                     ILoggerFactory loggerFactory,
                                     IConnectionManager sessionManager,
                                     IPlacement placement)

        {
            this.serviceProvider      = serviceProvider;
            this.logger               = loggerFactory.CreateLogger("MessageHandler");
            this.messageCenter        = messageCenter;
            this.sessionManager       = sessionManager;
            this.placement            = placement;
            this.clientConnectionPool = serviceProvider.GetService <ClientConnectionPool>();

            this.messageCenter.RegisterMessageProc(new BlockMessageCodec().CodecName, this.ProcessWebSocketMessage, false);
            this.messageCenter.RegisterDefaultMessageProc(this.ProcessDefaultMessage);
            this.RegisterHandler <ResponseAccountLogin>(this.ProcessResponseAccountLogin);
            this.RegisterHandler <RequestCloseSession>(this.ProcessRequestCloseSession);
            this.RegisterHandler <RequestSendMessageToSession>(this.ProcessRequestSendMessageToSession);
            this.RegisterHandler <RequestHeartBeat>(this.ProcessRequestHeartBeat);
            this.RegisterHandler <ResponseHeartBeat>(this.ProcessResponseHeartBeat);
        }
    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());
        }
    }
Esempio n. 9
0
 public ClientService(ClientConnectionPool ConnectionPool)
 {
     this.ConnectionPool = ConnectionPool;
 }
Esempio n. 10
0
 public ClientService(ClientConnectionPool ConnectionPool)
 {
     this .ConnectionPool = ConnectionPool ;
 }
Esempio n. 11
0
 /// <summary>
 /// cTor: submit the webserver as host:port (localhost:8080  or 192.168.1.10:9000 ..)
 /// </summary>
 /// <param name="host_port">Host and port to use in http request</param>
 public WebRequestor( )
 {
     m_client         = new HttpClient( );
     m_connectionPool = new ClientConnectionPool( );
 }