Thread Array aus String (3 answers)
Opened by Gast at 2007-06-27 19:48

bloonix
 2007-06-28 02:33
#227 #227
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Liegen die Daten auf dem Server als String oder schon als Array vor?
Man könnte natürlich auch das Array über das Socket senden :)

server.pl
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
use strict;
use warnings;
use IO::Socket::SIPC;

my $sipc = IO::Socket::SIPC->new( favorite => 'IO::Socket::INET' );

$sipc->connect(
  LocalAddr       => 'localhost',
  LocalPort       => 50010,
  Proto           => 'tcp',
  Listen          => 10,
  Reuse           => 1,
) or die $sipc->errstr($@);

warn "server initialized\n";

my @data = ( "handlung", "private", "nick", '<font face="Comic Sans MS " color="003300"> g</font>' );

while ( 1 ) {
  while (my $client = $sipc->accept()) {
     print "connect from client: ", $client->sock->peerhost, "\n";
     $client->send(\@data) or die $client->errstr($!);
     $client->disconnect or die $client->errstr($!);
  }  
  warn "server runs on a timeout, re-listen on socket\n";
}

$sipc->disconnect or die $sipc->errstr($!);


client.pl
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use strict;
use warnings;
use Data::Dumper;
use IO::Socket::SIPC;

my $sipc = IO::Socket::SIPC->new( favorite => 'IO::Socket::INET' );

$sipc->connect(
  PeerAddr        => 'localhost',
  PeerPort        => 50010,
  Proto           => 'tcp',
) or die $sipc->errstr($@);

warn "client connected to server\n";

my $data = $sipc->read or die $sipc->errstr($!);
warn "server data: \n";
warn Dumper($data);
$sipc->disconnect or die $sipc->errstr($!);


Ausgabe des Clients:

client connected to server
server data:
$VAR1 = [
         'handlung',
         'private',
         'nick',
         '<font face="Comic Sans MS " color="003300"> g</font>'
       ];
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 Array aus String