[Mono-dev] HTTP Protocol Implementation: Solving the message boundary problem

Robert Jordan robertj at gmx.net
Tue Dec 20 08:29:27 EST 2005


Vladimir,

> I wanted to ask a quick question about how the HTTPListener etc...
> classes solve the message boundary problem.
> 
> I took a look at the related classes, and it seems that the http
> commands are passed by reading/writing to a MemoryStream and
> delimiting each command by a "\r\r\n\n" in the ASCII encoding. Is that

It's actually "\r\n\r\n".

> correct? I am interested because I am doing Socket (tcp) programming
> at the moment, and it would be useful to hear what kind of workarounds
> there are for the message boundary problem, in, say, an XML-based
> protocol over TCP, something that is very similar in spirit to HTTP.

There is no such thing like a "message boundary problem". The HTTP
protocol separates only *the headers* with CRLF. Everthing else
(the part after the first empty line up to EOS) is up to the
application and it depends on the content type.

If you need something like "command batching" (like HTTP keep alives),
then you need to transfer something like a content-length header
before the payload. On the opposite side you read exactly content-length
bytes, so you know where the next message starts.

Have a look at HTTP's RFCs, and BTW, you should consider reusing
standard protocols instead of cooking your own ;-)

Robert




More information about the Mono-devel-list mailing list