SocketTools .NET Edition

TelnetClient.ReadLine Method (String, Int32)

Read up to a line of data from the server and return it in a string buffer.

[Visual Basic]
Overloads Public Function ReadLine( _
   ByRef buffer As String, _
   ByVal length As Integer _
) As Boolean
[C#]
public bool ReadLine(
   ref string buffer,
   int length
);

Parameters

buffer

A string which will contain the data read from the socket.

length
An integer value which specifies the maximum number of bytes of data to read.

Return Value

This method returns a boolean value which specifies if a line of data has been read. A value of true indicates a line of data has been read. If an error occurs or there is no more data available to read, then the method will return false. It is possible for data to be returned in the string buffer even if the return value is false. Applications should check the length of the string after the method returns 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 method return value.

Remarks

The ReadLine method reads data from the server up to the specified number of bytes or until an end-of-line character sequence is encountered. 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 variable. When an end-of-line character sequence is encountered, the method will stop and return the data up to that point; the string will not contain the carriage-return or linefeed characters.

There are some limitations when using the ReadLine method. The method should only be used to read text, never binary data. In particular, it will discard nulls, linefeed and carriage return control characters. This method will force the current thread to block until an end-of-line character sequence is processed, the read operation times out or the remote host closes its end of the socket connection. If the Blocking property is set to false, calling this method will automatically switch the client into a blocking mode, read the data and then restore the client to non-blocking mode. If another network operation is attempted while ReadLine is blocked waiting for data from the remote host, an error will occur. It is recommended that this method only be used with blocking connections.

The Read and ReadLine methods can be intermixed, however be aware that the Read method will consume any data that has already been buffered by the ReadLine method and this may have unexpected results.

See Also