Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSocket
LOCAL lnBTls
LOCAL lnMaxWaitMs
LOCAL lnBAvailable

lnSuccess = 0

loSocket = CreateObject('Chilkat.Socket')

*  Connect to the server using TLS.
lnBTls = 1
lnMaxWaitMs = 5000
lnSuccess = loSocket.Connect("example.com",5000,lnBTls,lnMaxWaitMs)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    CANCEL
ENDIF

*  Perform a nonblocking check for readable data.  Returns 1 when data or another read-ready
*  condition is present, and 0 when nothing is immediately available.
lnBAvailable = loSocket.PollDataAvailable()
IF (lnBAvailable <> 1) THEN
    ? "No data is immediately available."
ELSE
    ? "Data is available to read."
ENDIF

RELEASE loSocket