Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oSocket
LOCAL nBTls
LOCAL nMaxWaitMs
LOCAL nBAvailable
nSuccess := 0
oSocket := CreateObject("Chilkat.Socket")
// Connect to the server using TLS.
nBTls := 1
nMaxWaitMs := 5000
nSuccess := oSocket:Connect("example.com", 5000, nBTls, nMaxWaitMs)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
RETURN
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.
nBAvailable := oSocket:PollDataAvailable()
IF (nBAvailable != 1)
? "No data is immediately available."
ELSE
? "Data is available to read."
ENDIF
oSocket:destroy()