Sample code for 30+ languages & platforms
Perl

Duplicate a Socket Wrapper Sharing the Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.

Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.

Chilkat Perl Downloads

Chilkat2 Perl
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;
}

# Create a second Socket wrapper that shares this object's underlying connection.  Both wrappers
# operate on the same live connection; the shared connection is reference-counted.
my $dupSock = Chilkat2::Socket->new;
$success = $socket->DupSocket($dupSock);
if (!$success) {
    print $socket->LastErrorText, "\n";
    exit;
}

print "Duplicate socket wrapper created.\n";