Perl
Chilkat2 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
use strict;
use warnings;
use Chilkat2;
my $socket = Chilkat2::Socket->new;
# Connect to the server using TLS.
my $bTls = 1;
my $maxWaitMs = 5000;
my $success = $socket->Connect('example.com', 5000, $bTls, $maxWaitMs);
if (!$success) {
print $socket->LastErrorText, "\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.
my $bAvailable = $socket->PollDataAvailable();
if (!$bAvailable) {
print "No data is immediately available.\n";
} else {
print "Data is available to read.\n";
}