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

bloonix
 2006-08-20 18:36
#69017 #69017
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo zusammen,

also ich habe CPAN:Storable mal ausprobiert.

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
use strict;
use warnings;

package Server;

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

sub run {
  my $server = IO::Socket::INET->new( LocalPort  => 43610
                                    , Type       => SOCK_STREAM
                                    , Listen     => 10
                                    , Reuse      => 1
                                    ) or die $!;

  while (my $client = $server->accept()) {
     my $data = fd_retrieve($client);
     close $client;
     close $server;
     print Dumper($data);
  }
}

package Client;

use Storable qw(store_fd);
use IO::Socket::INET;

sub run {
  sleep 1;
  my $socket = IO::Socket::INET->new( PeerAddr => '127.0.0.1'
                                    , PeerPort => 43610
                                    , Proto    => 'tcp'
                                    , Type     => SOCK_STREAM
                                    ) or die $!;

  my %hash = (a=>1,b=>2,c=>3);
  store_fd \%hash, $socket;
}

1;

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


Gibt es hierbei irgendetwas zu beachten? Wie sicher ist das?

Grüße,
opi
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