Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
set socket [new_CkSocket]
# Connect to the server using TLS.
set bTls 1
set maxWaitMs 5000
set success [CkSocket_Connect $socket "example.com" 5000 $bTls $maxWaitMs]
if {$success == 0} then {
puts [CkSocket_lastErrorText $socket]
delete_CkSocket $socket
exit
}
# 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.
set bAvailable [CkSocket_PollDataAvailable $socket]
if {$bAvailable != 1} then {
puts "No data is immediately available."
} else {
puts "Data is available to read."
}
delete_CkSocket $socket