Peek - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


Sockets

  

Peek

  

check for data on a socket

 

Calling Sequence

Parameters

Description

Examples

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

> 

with⁡Sockets:

> 

sid≔Open⁡localhost,echo:

> 

Write⁡sid,Sample data:

> 

Peek⁡sid

Sample data

(1)
> 

Read⁡sid

Sample data

(2)
> 

Peek⁡sid

false

(3)
> 

Write⁡sid,Sample data:

> 

whilePeek⁡sid≠falsedoRead⁡sidenddo

Sample data

(4)
> 

Close⁡sid

true

(5)

See Also

Sockets

Sockets/timeout

Sockets[Read]

Sockets[ReadBinary]

Sockets[ReadLine]