Sockets - Maple Help

# Online Help

###### All Products    Maple    MapleSim

Sockets

 Peek
 check for data on a socket

 Calling Sequence Peek(sid)

Parameters

 sid - valid open socket ID

Description

 • 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.

Examples

 > $\mathrm{with}\left(\mathrm{Sockets}\right):$
 > $\mathrm{sid}≔\mathrm{Open}\left("localhost","echo"\right):$
 > $\mathrm{Write}\left(\mathrm{sid},"Sample data"\right):$
 > $\mathrm{Peek}\left(\mathrm{sid}\right)$
 ${"Sample data"}$ (1)
 > $\mathrm{Read}\left(\mathrm{sid}\right)$
 ${"Sample data"}$ (2)
 > $\mathrm{Peek}\left(\mathrm{sid}\right)$
 ${\mathrm{false}}$ (3)
 > $\mathrm{Write}\left(\mathrm{sid},"Sample data"\right):$
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{Peek}\left(\mathrm{sid}\right)\ne \mathrm{false}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{Read}\left(\mathrm{sid}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}$
 ${"Sample data"}$ (4)
 > $\mathrm{Close}\left(\mathrm{sid}\right)$
 ${\mathrm{true}}$ (5)

 See Also

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam