Beispiel #1
0
 private static void RemoveConnection(HeyHttpServerThread connection)
 {
     lock (connectionsLock)
     {
         connections.Remove(connection);
     }
 }
Beispiel #2
0
        private static void DoHttp(HeyLogger logger, Stream sslStream, Socket clientSocket)
        {
            HeyHttpServerThread connection = new HeyHttpServerThread(
                logger,
                clientSocket,
                null);

            connection.Accept(sslStream);
        }
Beispiel #3
0
        private static void Start()
        {
            // Trap CTRL + C.
            Console.CancelKeyPress += OnCancelKeyPress;

            // Dual-stack mode: TcpListerner.Create() listens on both, IPAddress.Any and IPAddress.IPv6Any.
            TcpListener tcpListener = TcpListener.Create(settings.Port);

            tcpListener.Start();
            Console.WriteLine("Listening on port {0} ...", settings.Port);

            while (true)
            {
                try
                {
                    var logger = settings.LoggerFactory.GetLogger();
                    logger.IsBodyLogEnabled = !settings.OnlyHeadersLog;

                    TcpClient           tcpClient  = tcpListener.AcceptTcpClient();
                    HeyHttpServerThread connection = new HeyHttpServerThread(
                        logger,
                        tcpClient.Client,
                        RemoveConnection);

                    lock (connectionsLock)
                    {
                        connections.Add(connection);
                    }

                    connection.Start();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }