Ich habe jetzt ein paar Stündchen noch rumgespielt, weil ganz plötzlich
die Übertragung der Daten via IO::Socket::SSL und Storable funktionierte
und bin auf was seltsames gestoßen.
my %hash1 = ( a => 1 );
my %hash2 = ( a => '1' );
%hash1 lässt sich sauber übertragen, %hash2 nicht. Das ist echt verflucht!
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;
}
Die Ausgabe ist:
server initialized
client connected to server
client request: hash
$VAR1 = {
'a' => 1
};
$VAR1 = {
'1' => 2,
'3' => 4
};
$VAR1 = undef;
Natürlich werden Strings auch mit Hochkomma oder doppelten
Hochkomma umschlossen und dann wird der ganze Hash einfach nicht
übertragen. Das ist echt zum verrückt werden.
Ich glaube aber trotzdem nicht, dass das Problem an Storable liegt, da ich
den Hash problemlos im gleichen Skript freeze'n und thaw'n kann und auch
über IO::Socket::INET.\n\n
<!--EDIT|opi|1163891933-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.