The ReadLine method reads data from the server and copies
into a specified string buffer. Unlike the Read method which
reads arbitrary bytes of data, this method is specifically designed
to return a single line of text data in a string.
When an end-of-line character sequence is encountered, the method
will stop and return the data up to that point. The string buffer is
guaranteed to be null-terminated and will not contain the end-of-line
characters.
There are some limitations when using ReadLine. The method
should only be used to read text, never binary data. In particular,
the method will discard nulls, linefeed and carriage return control
characters. The Unicode version of this method will return a Unicode
string, however it does not support reading raw Unicode data from the
socket. Any data read from the socket is internally buffered as
octets (eight-bit bytes) and converted to Unicode using the
MultiByteToWideChar function.
This method will force the thread to block until an end-of-line
character sequence is processed, the read operation times out or the
server closes its end of the socket connection. If this method
is called with asynchronous events enabled, it will automatically
switch the socket into a blocking mode, read the data and then
restore the socket to asynchronous operation. If another socket
operation is attempted while ReadLine is blocked waiting for
data from the server, an error will occur. It is recommended
that this method only be used with blocking (synchronous) socket
connections; if the application needs to establish multiple
simultaneous connections, it should create worker threads to manage
each connection.
The Read and ReadLine method calls can be
intermixed, however be aware that Read will consume any data
that has already been buffered by the ReadLine method and this
may have unexpected results.
Unlike the Read method, it is possible for data to be
returned in the string buffer even if the return value is zero.
Applications should check the length of the string to determine if
any data was copied into the buffer. For example, if a timeout occurs
while the method is waiting for more data to arrive on the socket, it
will return zero; however, data may have already been copied into the
string buffer prior to the error condition. It is the responsibility
of the application to process that data, regardless of the return
value.