Start() public method

public Start ( ) : void
return void
 /// <summary>
 /// TODO apply networking options, e.g. NO DELAY, LINGER, etc.
 /// </summary>
 public void Run()
 {
     tcpListener_.Start();
     while (State.RUNNING == ReactorState)
     {
         try
         {
             TcpClient client = tcpListener_.AcceptTcpClient();
             ApplySocketOptions(client);
             ClientHandlerThread t = new ClientHandlerThread(client, nextClientId_++);
             lock (sync_)
             {
                 clientThreads_.AddLast(t);
             }
             // FIXME set the client thread's exception handler here
             t.Log("connected");
             t.Start();
         }
         catch (System.Exception e)
         {
             if (State.RUNNING == ReactorState)
                 this.Log("Error accepting connection: " + e.Message);
         }
     }
     ShutdownClientHandlerThreads();
 }
 /// <summary>
 /// TODO apply networking options, e.g. NO DELAY, LINGER, etc.
 /// </summary>
 public void Run()
 {
     tcpListener_.Start();
     while (State.RUNNING == ReactorState)
     {
         try
         {
             TcpClient client = tcpListener_.AcceptTcpClient();
             ApplySocketOptions(client, socketSettings_);
             ClientHandlerThread t = new ClientHandlerThread(client, nextClientId_++);
             lock (sync_)
             {
                 clientThreads_.AddLast(t);
             }
             // FIXME set the client thread's exception handler here
             t.Log("connected");
             t.Start();
         }
         catch (System.Exception e)
         {
             if (State.RUNNING == ReactorState)
             {
                 this.Log("Error accepting connection: " + e.Message);
             }
         }
     }
     ShutdownClientHandlerThreads();
 }
Esempio n. 3
0
        /// <summary>
        /// TODO apply networking options, e.g. NO DELAY, LINGER, etc.
        /// </summary>
        public void Run()
        {
            lock (sync_)
            {
                if (State.SHUTDOWN_REQUESTED != state_)
                {
                    try
                    {
                        tcpListener_.Start();
                    }
                    catch (Exception e)
                    {
                        this.Log("Error starting listener: " + e.Message);
                        throw;
                    }
                }
            }

            while (State.RUNNING == ReactorState)
            {
                try
                {
                    TcpClient client = tcpListener_.AcceptTcpClient();
                    if (State.RUNNING == ReactorState)
                    {
                        ApplySocketOptions(client, socketSettings_);
                        ClientHandlerThread t =
                            new ClientHandlerThread(client, nextClientId_++, sessionDict_, socketSettings_, acceptorDescriptor_);
                        t.Exited += OnClientHandlerThreadExited;
                        lock (sync_)
                        {
                            clientThreads_.Add(t.Id, t);
                        }

                        // FIXME set the client thread's exception handler here
                        t.Log("connected");
                        t.Start();
                    }
                    else
                    {
                        client.Dispose();
                    }
                }
                catch (System.Exception e)
                {
                    if (State.RUNNING == ReactorState)
                    {
                        this.Log("Error accepting connection: " + e.Message);
                    }
                }
            }
            tcpListener_.Server.Close();
            tcpListener_.Stop();
            ShutdownClientHandlerThreads();
        }
Esempio n. 4
0
        /// <summary>
        /// TODO apply networking options, e.g. NO DELAY, LINGER, etc.
        /// </summary>
        public void Run()
        {
            lock (GdaxPrototyping.Common.Core.Threading.TThreadingHelpers.MainLockable)
            {
                if (State.SHUTDOWN_REQUESTED != state_)
                {
                    tcpListener_.Start();
                }
            }

            while (State.RUNNING == ReactorState)
            {
                try
                {
                    TcpClient client = tcpListener_.AcceptTcpClient();
                    ApplySocketOptions(client, socketSettings_);
                    ClientHandlerThread t = new ClientHandlerThread(client, nextClientId_++, sessionDict_, socketSettings_);
                    t.Exited += OnClientHandlerThreadExited;
                    lock (GdaxPrototyping.Common.Core.Threading.TThreadingHelpers.MainLockable)
                    {
                        clientThreads_.Add(t.Id, t);
                    }
                    // FIXME set the client thread's exception handler here
                    t.Log("connected");
                    t.Start();
                }
                catch (System.Exception e)
                {
                    if (State.RUNNING == ReactorState)
                    {
                        this.Log("Error accepting connection: " + e.Message);
                    }
                }
            }
            ShutdownClientHandlerThreads();
        }
Esempio n. 5
0
        /// <summary>
        /// TODO apply networking options, e.g. NO DELAY, LINGER, etc.
        /// </summary>
        public void Run()
        {
            lock (sync_)
            {
                if (State.SHUTDOWN_REQUESTED != state_)
                {
                    try
                    {
                        tcpListener_.Start();
                    }
                    catch (Exception e)
                    {
                        this.Log("Error starting listener: " + e.Message);
                        throw;
                    }
                }
            }

            while (State.RUNNING == ReactorState)
            {
                try
                {
                    TcpClient client = tcpListener_.AcceptTcpClient();
                    if (socketSettings_.SocketCountPerHost.HasValue)
                    {
                        var address = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
                        lock (sync_)
                        {
                            if (clientThreads_.Values.Count(c => c.SourceAddress == address) >= socketSettings_.SocketCountPerHost)
                            {
                                client.Dispose();
                                Log($"Limit of connections per host was reached for '{address}'");
                                continue;
                            }
                        }
                    }


                    if (State.RUNNING == ReactorState)
                    {
                        ApplySocketOptions(client, socketSettings_);
                        ClientHandlerThread t =
                            new ClientHandlerThread(client, nextClientId_++, sessionDict_, socketSettings_, acceptorDescriptor_);
                        t.Exited += OnClientHandlerThreadExited;
                        lock (sync_)
                        {
                            clientThreads_.Add(t.Id, t);
                        }

                        // FIXME set the client thread's exception handler here
                        t.Log("connected");
                        t.Start();
                    }
                    else
                    {
                        client.Dispose();
                    }
                }
                catch (System.Exception e)
                {
                    if (State.RUNNING == ReactorState)
                    {
                        this.Log("Error accepting connection: " + e.Message);
                    }
                }
            }
            tcpListener_.Server.Close();
            tcpListener_.Stop();
            ShutdownClientHandlerThreads();
        }
        /// <summary>
        /// TODO apply networking options, e.g. NO DELAY, LINGER, etc.
        /// </summary>
        public void Run()
        {
            lock (sync_)
            {
                if (State.SHUTDOWN_REQUESTED != state_)
                    tcpListener_.Start();
            }

            while (State.RUNNING == ReactorState)
            {
                try
                {
                    TcpClient client = tcpListener_.AcceptTcpClient();
                    ApplySocketOptions(client, socketSettings_);
                    ClientHandlerThread t = new ClientHandlerThread(client, nextClientId_++, sessionDict_, socketSettings_);
                    t.Exited += OnClientHandlerThreadExited;
                    lock (sync_)
                    {
                        clientThreads_.Add(t.Id, t);
                    }
                    // FIXME set the client thread's exception handler here
                    t.Log("connected");
                    t.Start();
                }
                catch (System.Exception e)
                {
                    if (State.RUNNING == ReactorState)
                        this.Log("Error accepting connection: " + e.Message);
                }
            }
            ShutdownClientHandlerThreads();
        }