Sample code for 30+ languages & platforms
Lianja

Poll a Socket for Available Data

See more Socket/SSL/TLS Examples

Demonstrates Socket.PollDataAvailable, which performs a nonblocking check for readable activity and returns whether data or another read-ready condition is present.

Background. This lets an application check for incoming data without blocking, for example in an event loop that services multiple tasks.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

loSocket = createobject("CkSocket")

//  Connect to the server using TLS.
llBTls = .T.
lnMaxWaitMs = 5000
llSuccess = loSocket.Connect("example.com",5000,llBTls,lnMaxWaitMs)
if (llSuccess = .F.) then
    ? loSocket.LastErrorText
    release loSocket
    return
endif

//  Perform a nonblocking check for readable data.  Returns .T. when data or another read-ready
//  condition is present, and .F. when nothing is immediately available.
llBAvailable = loSocket.PollDataAvailable()
if (llBAvailable <> .T.) then
    ? "No data is immediately available."
else
    ? "Data is available to read."
endif



release loSocket