Chilkat2-Python
Chilkat2-Python
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 Chilkat2-Python Downloads
import sys
import chilkat2
success = False
socket = chilkat2.Socket()
# Connect to the server using TLS.
bTls = True
maxWaitMs = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
if (success == False):
print(socket.LastErrorText)
sys.exit()
# 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.
bAvailable = socket.PollDataAvailable()
if (bAvailable != True):
print("No data is immediately available.")
else:
print("Data is available to read.")