Thread Hash Struktur senden: Client - Server (30 answers)
Opened by bloonix at 2006-08-20 07:23

bloonix
 2006-11-17 12:04
#69021 #69021
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo Community,

nun war ich lange Zeit mit CPAN:Storable sehr sehr zufrieden. Das Modul ist einfach klasse.
Allerdings läuft es nicht mit IO::Socket::SSL. Ich erhalte die Meldung

File is not a perl storable at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/fd_retrieve.al) line 346, at ./storable-socket-ssl line 61

Code: (dl )
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
use strict;
use warnings;

package Server;

use IO::Socket::SSL;
use Storable qw(nstore_fd);
use Data::Dumper;

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 %hash = (a=>1,b=>2,c=>3);
     nstore_fd(\%hash, $client) or die $!;
     close($client);
     close($socket);
  }
}

package Client;

use IO::Socket::SSL;
use Storable qw(fd_retrieve);
use Data::Dumper;

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

  warn "client connected to server\n";
  print $socket "hash\n";
  my $data = fd_retrieve($socket) or die $!;
  warn Dumper($data);
  close($socket);
}

1;

if (my $pid = fork) {
  run Server;
  waitpid($pid,0);
} else {
  sleep 1;
  run Client;
}


Dies ist das gleiche Beispiel wie oben, nur halt INET durch SSL ersetzt.

Wenn ich statt

my $data = fd_retrieve($socket) or die $!;

mit

local $/; my $data = <$socket>;

teste, dann ist $data undef.

Hat da jemand Ideen oder kennt eine Lösung?

Gruss,
opi\n\n

<!--EDIT|opi|1163758123-->
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.

View full thread Hash Struktur senden: Client - Server