use warnings; use strict; use IO::Socket::SSL; use constant { BUFSIZE => 16384 }; die 'Invalid BUFSIZE value (must be a multiple of 16)' if(BUFSIZE%16); my $LOCAL_ADDR='0.0.0.0'; my $LOCAL_PORT=1234; my $BUFFER = '0123456789ABCDEF' x (BUFSIZE/16); my $srvSock; $srvSock=IO::Socket::SSL->new( LocalHost => $LOCAL_ADDR, LocalPort => $LOCAL_PORT, ReuseAddr => 1, Listen => 1, SSL_cert_file => 'cert.pem', SSL_key_file => 'key.pem', ) or die "Failed to create listening SSL socket: $!"; print "SSL server listening on $LOCAL_ADDR:$LOCAL_PORT\n"; while() { print "Waiting for client to connect...\n"; my $clientSock = $srvSock->accept() or die "Failed to accept SSL client connection: $!, $SSL_ERROR\n"; print "Client connected, sending data.\n"; while() { my $writeLength=syswrite($clientSock,$BUFFER) or do { print " Failed to write to client: $!, $SSL_ERROR\n"; last; }; if($writeLength != BUFSIZE) { print " Unexpected write length: $writeLength\n"; last; } } }