check for data on a socket - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Connectivity : Web Features : Network Communication : Sockets Package : Sockets/Peek

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

withSockets:

sid:=Openlocalhost,echo:

Writesid,Sample data:

Peeksid

Sample data

(1)

Readsid

Sample data

(2)

Peeksid

false

(3)

Writesid,Sample data:

whilePeeksidfalsedoReadsidend do

Sample data

(4)

Closesid

true

(5)

See Also

socket definition, Sockets, Sockets/timeout, Sockets[Read], Sockets[ReadBinary], Sockets[ReadLine]


Download Help Document

Was this information helpful?



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