Exemple #1
0
        public void Listen()
        {
            bool done = false;

            listener = new TcpListener(IPAddress.Any, portNum);

            listener.Start();

            while (!done)
            {
                try
                {
                    WriteLog("Waiting for connection...");
                    var client = listener.AcceptTcpClient();
                    var ip     = ((IPEndPoint)client.Client.RemoteEndPoint).Address.Address;

                    if (IncreaseConnections(ip))
                    {
                        CsHTTPRequest newRequest
                            = new CsHTTPRequest(client, this);
                        Thread Thread = new Thread(new ThreadStart(newRequest.Process));
                        Thread.Name = "HTTP Request";
                        Thread.Start();

                        // threadpool is limited, use just a thread
                        //ThreadPool.QueueUserWorkItem(a => newRequest.Process());
                    }
                    else
                    {
                        client.Client.Close();
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
Exemple #2
0
        public void Listen()
        {
            bool done = false;

            listener = new TcpListener(IPAddress.Any, portNum);

            listener.Start();

            while (!done)
            {
                try
                {
                    WriteLog("Waiting for connection...");
                    var client = listener.AcceptTcpClient();
                    var ip = ((IPEndPoint)client.Client.RemoteEndPoint).Address.Address;

                    if (IncreaseConnections(ip))
                    {
                        CsHTTPRequest newRequest
                                       = new CsHTTPRequest(client, this);
                        Thread Thread = new Thread(new ThreadStart(newRequest.Process));
                        Thread.Name = "HTTP Request";
                        Thread.Start();

                        // threadpool is limited, use just a thread
                        //ThreadPool.QueueUserWorkItem(a => newRequest.Process());
                    }
                    else
                    {
                        client.Client.Close();
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }

        }