Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-29 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found