Client side contains Array of Hash how can it be sent to server side for data retrieval. Below code gives stub and it is not correct but provide network connection.
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);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.