Web server - how to analyze requests? Asynchronous flow tokenizer?

I am trying to create a simple web server in C # in an asynchronous socket programming style. The goal is very narrow - the comet server (http long-poll).

I have started the Windows service, accepting connections, downloading request data to the console and returning the client simple fixed content.

Now I cannot understand a guided strategy for analyzing query data asynchronously and safely. I already wrote synchronous partisans LL1. I am not sure if LL1 Parser is suitable or necessary for HTTP. I don't know how to tokenize an input stream asynchronously. All I can imagine is having an input buffer for each client, reading into it, and then copying this into a StringBuilder and periodically checking if I have a complete request. But this seems inefficient and can lead to complex code debugging / maintenance.

In addition, there are two connection phases for receiving a request in full and sending a response - in this case, after some delay. As soon as the request is verified and valid, only then do I plan to register the connection in the long polls manager. However, the wrong client can continue to send data and fill the buffer, so I think I need to continue to monitor and clear the input stream during the response phase, right?

Any recommendations on this subject are welcome.

I guess the first step is to know if it is possible to efficiently tokenize the network stream asynchronously and without a large intermediate buffer. Even without the correct analyzer, the same problems when creating a tokenizer apply to reading the "lines" of the input at a time or even reading up to double empty lines (one large token). I do not want to read one byte at a time from the network, but I also do not want to read too many bytes and store them in some kind of intermediate buffer, right?

+5
source share
1 answer

HTTP ( \r\n\r\n), \r\n, : .

.

+2

All Articles