This project is read-only.

help creating my C# webserver

Jul 1, 2010 at 10:59 PM

Hi all

I need to program my own webserver in C# using sockets that can recive files from html-pages.

When I have recived and read the request I have a long bytearray that contain all the httprequest.

Thats off course sligthly advanced to understand and retract files from.

Do any clases exist that can help me interpret the httprequest?

I cant use httplistener class. I has to be with sockets but I'd like to know how the httplistener interprets.

Or any other suggestions?

Kin regards


Copenhagen, Denmark

Jul 2, 2010 at 8:29 AM

I don't understand why you can't use the HttpListener? It's built ontop of sockets. What the HTTPListener does is to parse the incoming byte stream and convert it into a HttpRequest object.


Jul 2, 2010 at 9:14 AM

After reading your question a bit more careful:

You can use the HttpParser from your socket.

Call the parser.Parse method with your bytearray. The return value indicates index where the parsing stopped. The parser can stop if the isn't enough bytes to continue (send TCP is stream oriented and not message oriented) or if a complete message have been parsed. You don't really have to know why the parsing stop, just remove all bytes before the returned index and continue to read from your socket. Check the HttpContext for an example.