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

In reply to Send an Array of Hash in Socket by muthuma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.