Perl
Chilkat2 Perl
Move a Connection into a Socket Set
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeSocket, which moves a connection into a newly created member of this object's socket set. After one or more calls, the object acts as a set of sockets.
Background. A socket set groups multiple connections so they can be monitored together with the SelectForReading and SelectForWriting methods. After success, the source socket holds no connection.
Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
my $listenSock = Chilkat2::Socket->new;
my $success = $listenSock->BindAndListen(5000, 25);
if (!$success) {
print $listenSock->LastErrorText, "\n";
exit;
}
my $connectedSock = Chilkat2::Socket->new;
$success = $listenSock->AcceptNext(20000, $connectedSock);
if (!$success) {
print $listenSock->LastErrorText, "\n";
exit;
}
# Move the connection out of connectedSock and into a newly created member of this object's socket
# set. After one or more such calls, socketSet acts as a set of connected sockets (useful with the
# SelectForReading / SelectForWriting methods). After success, connectedSock holds no connection.
my $socketSet = Chilkat2::Socket->new;
$success = $socketSet->TakeSocket($connectedSock);
if (!$success) {
print $socketSet->LastErrorText, "\n";
exit;
}
print "Connection added to the socket set.\n";