Пример #1
0
        /// <summary>
        /// Generates reply using the socket stream
        /// </summary>
        /// <param name="networkStreamWriter"></param>
        /// <param name="request"></param>
        private static async Task GenerateReplyToRequest(NetworkStream networkStreamWriter, RawHttpRequest request)
        {
            // Echo the data back to the client.
            HttpResponse response;
            IHttpParser  parser;

            if (request.Type == HttpRequestType.Get)
            {
                parser   = new GetParser(request.Content);
                response = parser.ParseHttpRequest();
            }
            else if (request.Type == HttpRequestType.Post)
            {
                parser   = new PostParser(request.Content);
                response = parser.ParseHttpRequest();
            }
            else
            {
                Console.WriteLine("[DEBUG]TEST Message received sucessfully...");
                var testReply = "[REPLY]Echo Complete...".GetBytes();
                await networkStreamWriter.WriteAsync(testReply, 0, testReply.Length);

                return;
            }
            Console.WriteLine("Response:" + response.StatusCode);
            byte[] reply = response.Construct();
            await networkStreamWriter.WriteAsync(reply, 0, reply.Length);
        }
Пример #2
0
        private static void GenerateReplyToRequest(Socket handler, string content)
        {
            // Convert the string data to byte data using ASCII encoding.
            //byte[] replyData = Encoding.ASCII.GetBytes(content);

            var parser = new GetParser(content);


            var response = parser.ParseHttpGet();

            // Begin sending the data to the remote device.
            //var replyString = String.Join(" - ", strings).GetBytes();
            var replyStringBytes =
                "<HTML>\r\n<HEAD>\r\n<TITLE>Hello World in HTML</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<CENTER><H1>Hello World!</H1></CENTER>\r\n</BODY>\r\n</HTML>"
                .GetBytes();



            handler.BeginSend(replyStringBytes, 0, replyStringBytes.Length, 0, CompleteSend, handler);
        }