The WriteLine method writes a line of text to the remote
host and terminates the line with a carriage-return and linefeed
control character sequence. Unlike the Write method which
writes arbitrary bytes of data to the socket, the WriteLine
method is
specifically designed to write a single line of text data from a
null-terminated string. This method will force the session thread to
block until the complete line of text has been written, the write
operation times out or the remote host aborts the connection.
There are some limitations when using WriteLine. This
method should only be used to send text, never binary data. In
particular, it will discard nulls and append linefeed and carriage
return control characters to the data stream. The Unicode version of
this method will accept a Unicode string, however it does not support
writing raw Unicode data to the socket. Unicode strings will be
automatically converted to UTF-8 encoding using the
WideCharToMultiByte function and then written to the socket as
a stream of bytes.
The Write and WriteLine methods can be safely
intermixed.
Unlike the Write method, it is possible for data to have
been written to the socket if the return value is zero. For example,
if a timeout occurs while the method is waiting to send more data to
the remote host, it will return zero; however, some data may have
already been written prior to the error condition. If this is the
case, the lpnLength argument will specify the number of
characters actually written up to that point.