SocketReadyQ

SocketReadyQ[socket]

tests if there is any data immediately available to read from the specified socket.

SocketReadyQ[socket,t]

waits for up to t seconds to see if data becomes available to read.

Details

  • Sockets in SocketReadyQ[] are specified using SocketObject[].
  • SocketReadyQ returns immediately; unlike Read etc., it does not block waiting for data to become available.
  • For numeric values, t is interpreted as having units of seconds. A time Quantity can also be used.

Examples

open allclose all

Basic Examples  (3)

Initially on connection, most websites will not send data until a request is made:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Write a request to the socket and wait for up to 10 seconds for the server's response to arrive:

In[3]:=
Click for copyable input
Out[3]=

Close the socket:

In[4]:=
Click for copyable input
Out[4]=

Open a server socket and connect a client socket to it:

In[1]:=
Click for copyable input
Out[1]=
Out[1]=

Initially, neither of them has any data available:

In[2]:=
Click for copyable input
Out[2]=

Sending a message to the client makes the socket ready for reading:

In[3]:=
Click for copyable input
Out[3]=

After reading the message, there is no more data available:

In[4]:=
Click for copyable input
Out[4]=

Close the sockets:

In[5]:=
Click for copyable input
Out[5]=

Wait for a response using a Quantity as the second argument:

In[1]:=
Click for copyable input
Out[1]=

Close the socket:

In[2]:=
Click for copyable input
Out[2]=

Neat Examples  (1)

See Also

SocketWaitNext  SocketWaitAll  Read  LinkReadyQ

Introduced in 2017
(11.2)