Peek Method  
 

Return data read from the specified client session, but do not remove it from the socket buffer.

Syntax

object.Peek( Handle, Buffer, [Length] )

Parameters

Handle
An integer value that specifies the handle to the client session.
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

If the method succeeds, it will return the number of bytes available to read from the socket without causing the thread to block. A return value of zero indicates that there is no data available to read at that time. If an error occurs, a value of -1 is returned.

Remarks

The Peek method reads the specified number of bytes from the specified socket and copies them into the buffer, but it does not remove the data from the internal socket buffer. Note that it is possible for the returned data to contain embedded null characters.

The data returned by the Peek method is not removed from the socket buffers. It must be consumed by a subsequent call to the Read method. The return value indicates the number of bytes that can be read in a single operation, up to the specified buffer size. However, it is important to note that it may not indicate the total amount of data available to be read from the socket at that time.

If no data is available to be read, the method will return a value of zero. Using this method in a loop to poll a socket may cause the server application to become non-responsive. To determine if there is data available to be read, use the IsReadable property.

See Also

IsReadable Property, Read Method, ReadLine Method, Write Method, WriteLine Method, OnRead Event, OnWrite Event