Sample code for 30+ languages & platforms
Perl

Receive Bytes up to a Delimiter into a BinData

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.

Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.

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

# Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
# delimiter to a BinData.  The delimiter is a raw byte value from 0 through 255 (here the linefeed
# byte, decimal 10).
my $bd = Chilkat2::BinData->new;
$success = $socket->ReceiveUntilByteBd(10, $bd);
if (!$success) {
    print $socket->LastErrorText, "\n";
    exit;
}

print 'Received ', $bd->NumBytes, " bytes (including the delimiter).\n";