Re: problem with sockets



<bofh1234@xxxxxxxxxxx> wrote in message
news:1146185148.496849.181500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thank you for the response. I thought that the loop did that because
of packetization. How do you make sure you have read all of the data?

Aside from an out-of-band signal, ie closing the connection, by implementing
a protocol that allows you to determine that, based on the data you have
read so far. The two most common methods are probably:

- Prefix "all of the data" with the length of that data.

- Follow "all of the data" with a terminating character or sequence (such as
carriage return followed by linefeed, CRLF). Either the terminating sequence
cannot appear in the data, or must be escaped in some manner when it does.

For instance, in HTTP, a response consists of a response line, headers,
blank line, and body in that order. Each header is terminated by CRLF, and
the length of the body may be specified in a "Content-Length" header.

In POP3, in response to a command to retrieve a message, the server sends a
response line, followed by each line of the message in turn, followed by a
line containing a single full stop (or period, ".") and nothing else. To
allow for messages that have lines containing only ".", the server uses an
escape: it prefixes any line in the message that begins with "." with
another ".".

Alex


.