Sample code for 30+ languages & platforms
Perl

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

Perl
use chilkat();

$success = 0;

$socket = chilkat::CkSocket->new();

#  Connect to the server using TLS.
$bTls = 1;
$maxWaitMs = 5000;
$success = $socket->Connect("example.com",5000,$bTls,$maxWaitMs);
if ($success == 0) {
    print $socket->lastErrorText() . "\r\n";
    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.
$bAvailable = $socket->PollDataAvailable();
if ($bAvailable != 1) {
    print "No data is immediately available." . "\r\n";
}
else {
    print "Data is available to read." . "\r\n";
}