Peek Method  
 

Read data returned by the server, but do not remove it from the receive buffer.

Syntax

object.Peek( Buffer, [Length] )

Parameters

Buffer
A buffer that the data will be stored in. If the variable is a String then the data will be returned as a string of characters. This is the most appropriate data type to use if the server is sending data that consists of printable characters. If the server is sending binary data, it is recommended that a Byte array be used instead. This parameter must be passed by reference.
Length
A numeric value which specifies the number of bytes to read. Its maximum value is 231-1 = 2147483647. This argument is required to be present for string data. If a value is specified for this argument for other permissible types of data, and it is less than number of bytes that is determined by the control, then Length will override the internally computed value. If the argument is omitted, then the maximum number of bytes to read is determined by the size of the buffer.

Return Value

The number of bytes actually read from the server is returned by this method. If there is no data available to be read, a value of zero is returned. If an error occurs, a value of -1 is returned.

Remarks

The Peek method can be used to examine the data that is available to be read from the internal receive buffer. If there is no data in the receive buffer at that time, a value of zero is returned. It should be noted that this differs from the Read method, where a return value of zero indicates that there is no more data available to be read and the connection has been closed. The Peek method will never cause the client to block, and so may be safely used with asynchronous connections. Note that it is possible for the returned data to contain embedded null characters.

See Also

IsConnected Property, IsReadable Property, Read Method, ReadLine Method, Search Method, Write Method, OnRead Event, OnWrite Event