Sample code for 30+ languages & platforms
CkPython

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 CkPython Downloads

CkPython
import sys
import chilkat

success = False

socket = chilkat.CkSocket()

#  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.")