Sockets
Peek
check for data on a socket
Calling Sequence
Parameters
Description
Examples
Peek(sid)
sid
-
valid open socket ID
By default, a read operation on a socket will block until data becomes available. The procedure Peek enables you to test for the presence of data on a socket. This is useful for avoiding the use of timeouts on calls to Sockets[Read], Sockets[ReadLine], or Sockets[ReadBinary].
The procedure Peek never blocks; either the value false or a string is returned immediately.
When Peek is called, it "samples" the data available on the socket without reading it. A string containing the data "sample" is returned. The same data will be available to the next call to Sockets[Read], Sockets[ReadLine], or Sockets[ReadBinary]. If no data is available on the socket, then the value false is returned.
with⁡Sockets:
sid≔Open⁡localhost,echo:
Write⁡sid,Sample data:
Peek⁡sid
Sample data
Read⁡sid
false
whilePeek⁡sid≠falsedoRead⁡sidenddo
Close⁡sid
true
See Also
socket definition
Sockets/timeout
Sockets[Read]
Sockets[ReadBinary]
Sockets[ReadLine]
Download Help Document