Пример #1
0
        public void DoWork()
        {
            try
            {
                listener = new TcpListener(ipaddress, port);
                listener.Start();
                while (isActive)
                {
                    TcpClient socket = listener.AcceptTcpClient();

                    if (RequestQueue.Count > numOfWorker * 2)
                    {
                        StreamWriter outputStream = new StreamWriter(new BufferedStream(socket.GetStream()));
                        HttpResponse.writeUnavalible(outputStream);
                        outputStream.Flush();
                        socket.Close();
                        continue;
                    }
                    RequestQueue.Add(socket);
                }
            }
            catch (Exception e)
            {
                listener.Stop();
                logger.Error(e.ToString(), e);
                Dispose();
                Environment.Exit(-99);
            }
        }