Leser: 1
|< 1 2 3 4 >| | 31 Einträge, 4 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use strict;
use warnings;
package Server;
use IO::Socket::SSL;
use Linux::Statistics;
use Storable qw(nfreeze);
unless (-d "certs") {
if (-d "../certs") {
chdir "..";
} else {
die "Please run this example from the IO::Socket::SSL distribution directory!\n";
}
}
sub run {
my $socket = IO::Socket::SSL->new(
Listen => 5,
LocalAddr => 'localhost',
LocalPort => 9000,
Proto => 'tcp',
Reuse => 1,
SSL_verify_mode => 0x01,
SSL_passwd_cb => sub {return "bluebell"},
) or die "server: can't open socket over port 9000";
warn "server initialized\n";
while (my $client = $socket->accept()) {
chomp (my $request = <$client>);
next unless $request;
warn "client request: $request\n";
my %hash1 = ( a => 1 );
my %hash2 = ( 1, 2, 3, 4 );
my %hash3 = ( a => '1' );
my $dump1 = nfreeze \%hash1;
my $dump2 = nfreeze \%hash2;
my $dump3 = nfreeze \%hash3;
print $client $dump1;
print $client "\n";
print $client $dump2;
print $client "\n";
print $client $dump3;
close($client);
close($socket);
}
}
package Client;
use IO::Socket::SSL;
use Storable qw(thaw);
use Data::Dumper;
use Safe;
sub run {
my $socket = IO::Socket::SSL->new(
PeerAddr => 'localhost',
PeerPort => '9000',
Proto => 'tcp',
SSL_use_cert => 1,
SSL_verify_mode => 0x01,
SSL_passwd_cb => sub { return "opossum" }
) or die "client: can't connect to 127.0.0.1:9000";
my $safe = new Safe;
$safe->permit(qw(:default require));
{
no warnings 'once';
$Storable::Deparse = 1;
$Storable::Eval = sub { $safe->reval($_[0]) };
}
warn "client connected to server\n";
print $socket "hash\n";
my $dump1 = <$socket>;
my $dump2 = <$socket>;
my $dump3 = <$socket>;
my $data1 = thaw($dump1);
my $data2 = thaw($dump2);
my $data3 = thaw($dump3);
close($socket);
warn Dumper($data1);
warn Dumper($data2);
warn Dumper($data3);
}
1;
if (my $pid = fork) {
run Server;
waitpid($pid,0);
} else {
sleep 1;
run Client;
}
|< 1 2 3 4 >| | 31 Einträge, 4 Seiten |