B4X
B4X
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 B4X Downloads
Dim success As Boolean = False
Dim socket As ChilkatSocket
socket.Initialize("socket")
' Connect to the server using TLS.
Dim bTls As Boolean = True
Dim maxWaitMs As Int = 5000
success = socket.Connect("example.com", 5000, bTls, maxWaitMs)
If success = False Then
Log(socket.LastErrorText)
Return
End If
' Perform a nonblocking check for readable data. Returns True when data or another read-ready
' condition is present, and False when nothing is immediately available.
Dim bAvailable As Boolean = socket.PollDataAvailable
If bAvailable <> True Then
Log("No data is immediately available.")
Else
Log("Data is available to read.")
End If