muthuma has asked for the wisdom of the Perl Monks concerning the following question:
SERVER use strict; use IO::Socket; use Sys::Hostname; use constant BUFSIZE => 1024; my $host = hostname; my $port = shift || '10280'; my $socket = new IO::Socket( Domain => PF_INET, Proto => getprotobyname('tcp'), LocalAddr => $host, LocalPort => $port, Listen => 1,#SOMAXCONN, #ReuseAddr => SO_REUSEADDR, ) or die $@; my $buffer; print "Waiting to do service...\n"; while (my $client =$socket->accept) { print "Client: ",$client->peerhost," Connected..\n"; syswrite($client,"Reached Server\n",BUFSIZE); my @AoH = (); if(sysread($client,$buffer,BUFSIZE)>0) { @AoH = unpack("a*",$buffer); print "AoH:",@AoH,"\n"; print $#AoH,"<= Length\n"; for my $i ( 0 .. $#AoH ) { print "Id = $i => {\n"; for my $param ( keys %{ $AoH[$i] } ) { print "\t$param=$AoH[$i]{$param}\n"; } print "}\n"; } } else { print "Client Disconnected..\n"; print "Waiting to do service...\n"; } print "Again to accept connection\n"; } CLIENT use strict; use IO::Socket; use constant BUFSIZE => 1024; my @AoH = ( { husband => "barney", wife => "betty", son => "bamm bamm", }, { husband => "george", wife => "jane", son => "elroy", }, { husband => "homer", wife => "marge", son => "bart", }, ); my $host = shift or die "Usage: client.pl host [port]\n"; my $port = shift || '10280'; my $socket = new IO::Socket(Domain => PF_INET, PeerAddr => $host, PeerPort => $port, Proto => getprotobyname('tcp'), Timeout => 60,) or die $@; my $buffer; if (sysread($socket,$buffer,BUFSIZE) > 0) { syswrite(STDOUT,$buffer); } print "AoH=",@AoH,"\n"; print "\t$param=$AoH[$i]{$param}\n"; # How to send the Array of Hash in one shot=> modification required in + below line #******** Monks can you pls suggest good idea??? syswrite($socket,pack("a*",@AoH),BUFSIZE);# only address is sent.. close($socket);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Send an Array of Hash in Socket
by ikegami (Patriarch) on Oct 22, 2008 at 08:59 UTC | |
|
Re: Send an Array of Hash in Socket
by andreas1234567 (Vicar) on Oct 22, 2008 at 08:06 UTC | |
|
Re: Send an Array of Hash in Socket
by BrowserUk (Patriarch) on Oct 22, 2008 at 08:07 UTC | |
|
Re: Send an Array of Hash in Socket
by Corion (Patriarch) on Oct 22, 2008 at 07:59 UTC | |
|
Re: Send an Array of Hash in Socket
by muthuma (Novice) on Oct 22, 2008 at 08:53 UTC |