Hi,

I am trying to pass a hash reference from server to client. I then try to print the content of the hash. However, there appears some error in my programs and the client does not print the output and simply hangs on its terminal.

Please let me know what is a good way to do this.

Thank you.

#tcpserver.pl #!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; use Storable qw(nfreeze); $| = 1; my ($socket,$clientsocket); my ($peeraddress,$peerport); my $data; my $line; my $inputfile = "list.txt"; my %names=(); my $reftohash; open(RF, "$inputfile"); # read file while ($line=<RF>) { chomp $line; $names{$line}=1; } #set hash reference $reftohash=\%names; $socket = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '5000', Proto => 'tcp', Listen => 5, Reuse => 1 ) or die "ERROR in Socket Creation : $!\n"; while(1) { $clientsocket = $socket->accept(); print $clientsocket nfreeze($reftohash); } $socket->close(); ########## #tcpclient.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use IO::Socket::INET; use Storable qw(thaw); $| = 1; my $socket; my $data; my $data1; $socket = new IO::Socket::INET ( PeerHost => 'localhost', PeerPort => '5000', Proto => 'tcp', ) or die "ERROR in Socket Creation : $!\n"; $data = <$socket>; $data1 = thaw($data); print "Received from Server : $data1\n"; foreach my $i (keys %{$data1}) { print "$i=>$data1->{$i}\n"; } $socket->close();

In reply to Passing hash reference over tcp client/server by newbio

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.