Exemplo n.º 1
0
        /// <summary>
        /// Handle specified http client
        /// </summary>
        /// <param name="client">Client to be handled</param>
        private void _handleClient(TcpClient client)
        {
            var stream = client.GetStream();

            //parse incoming http request
            var parser = new HTTPRequestParser();
            while (!parser.IsComplete)
                parser.AddData(stream.Read());

            ConsoleUtils.WriteLn(
                new Wr(ConsoleColor.Yellow, "{1} -> {0}", client.Client.LocalEndPoint, client.Client.RemoteEndPoint),
                new Wr(ConsoleColor.Green, parser.HeaderPart.Replace("{", "{{").Replace("}","}}"))
                );

            proceedRequest(parser, client);
        }
Exemplo n.º 2
0
        private HTTPRequestParser sendHTTP(string http, params object[] pars)
        {
            http = string.Format(http, pars);
            var tv = new TcpClient();
            var result = tv.BeginConnect(RemoteIP, RemotePort, null, null);

            var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5));
            if (!success)
            {
                return null;
            }

            // we have connected
            tv.EndConnect(result);

            var stream = tv.GetStream();
            stream.Write(http);
            var parser = new HTTPRequestParser();
            while (!parser.IsComplete)
            {
                var data = stream.Read();
                parser.AddData(data);
            }
            tv.Close();

            return parser;
        }