( doc | 2012. 08. 03., p – 12:07 )

lecsupaszitottam a ket scriptet, alant jonnek
legyszi kukkantsatok ra, hatha egybol kiszurjatok mi nem jo...
illetve ha ranezesre jo, akkor plz probaljatok ki, hogy nalatok megy-e
hatalmas koszi elore is!

SERVER:

#!/usr/bin/perl -w

use strict;
use warnings;
use IO::Socket::SSL;
$IO::Socket::SSL::DEBUG = 4;

my $CERT_FILE = "cert/localhost.crt";
my $KEY_FILE = "cert/localhost.key";

sub StartServer($)
{
my $port = shift;
my $socket = IO::Socket::SSL->new(
LocalPort => $port,
Reuse => 1,
Listen => 10,
Proto => 'tcp',
SSL_Server => 1,
SSL_cert_file => $CERT_FILE,
SSL_key_file => $KEY_FILE,
SSL_verify_mode => 0x00,
SSL_cipher_list => 'ALL',
#SSL_passwd_cb => sub {return ""}
) || die "ERROR: Can't start server on port $port: ".IO::Socket::SSL::errstr;
print "server started, listening on port $port\n";
$socket;
}

sub ListenLoop($)
{
my $socket = shift;
if (my $client = $socket->accept())
{
my $client_host = $client->host();
my $client_ip = $client->ip();
print "New connection from $client\n";
print while ();
print CLIENT Log("-- END ---");
print "connection closed: $client_host $client_ip";
close CLIENT;
}
else
{
print "WARNING: can't accept connection! ".IO::Socket::SSL::errstr."\n";
}
}

my $socket = StartServer(6543);
ListenLoop($socket) while(1);
$socket->close();

CLIENT:

#!/usr/bin/perl -w

use strict;
use warnings;
use IO::Socket::SSL;

$IO::Socket::SSL::DEBUG = 4;

sub Connect($$)
{
my ($server, $port) = @_;
my $socket = IO::Socket::SSL->new(
PeerAddr => $server,
PeerPort => $port,
#Reuse => 1,
Proto => 'tcp',
SSL_use_cert => 0,
SSL_cipher_list => 'ALL',
#SSL_use_cert => 1,
#SSL_cert_file => $CERT_FILE,
#SSL_verify_mode => 0x01,
#SSL_passwd_cb => sub {return ""}
) || die "ERROR: Can't connect to server $server:$port: ".IO::Socket::SSL::errstr."\t$!";
print "connected to server $server:$port\n";
$socket;
}

sub Close($)
{
my $socket = shift;
$socket->close();
}

my $socket = Connect("localhost", 6543);
$socket->write("testmessage");
Close($socket);