Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Serializing data using storable over socket

by kernelzack (Novice)
on Apr 11, 2011 at 23:20 UTC ( [id://898807]=perlquestion: print w/replies, xml ) Need Help??

kernelzack has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,
I am a beginner and am having some troubles over coming this issue. I have searched on the internet and have learned a lot in the process but have not been able to get past my roadblock.

I am having trouble sending a hash across a tcp socket I have setup. I am using the IO::Socket module to setup the client and server. I am running my tests on 2 freebsd 8.1 x64 machines. Here is a snippet of what I am trying to do:

#server code
my %hash = ('tom' => 'brady', 'brett' => 'favre');
$send_data = nfreeze(\%hash);
$client_socket->send($send_data);


#client code
$socket->recv($recv_data,1024);
my $ref = thaw($recv_data);
print $ref;


When i try to just print in the client code I get nothing. No errors and no output.

When I use this code in a simple test script it works as i expect. Here is my test code snippet not using sockets at all:

#local script
use Storable qw(nfreeze thaw);
my $hash = {'tom' => 'brady', 'brett' => 'favre'};
print my $test = nfreeze($hash);
print thaw($test);


Can anyone point me in the right direction as to why I can't get this to work over a tcp socket?

Thank you very much for your time. Sorry everyone, had to much to drink last night. I did not have $| set properly.... please disregard my stupidty. THanks
  • Comment on Serializing data using storable over socket

Replies are listed 'Best First'.
Re: Serializing data using storable over socket
by BrowserUk (Patriarch) on Apr 12, 2011 at 05:31 UTC
    When i try to just print in the client code I get nothing. No errors and no output.

    Have you tried printing the length of what you recv?

    Have you binmoded the sockets at both ends?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Serializing data using storable over socket
by Khen1950fx (Canon) on Apr 12, 2011 at 08:13 UTC
    As regards #local script without sockets, you might give this a try:
    #!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use Hash::AutoHash::MultiValued; use Storable qw(nfreeze thaw); my $mvhash = new Hash::AutoHash::MultiValued-> names(tom => 'brady', brett => 'favre'); my $test = nfreeze($mvhash); print dump(thaw($test)), "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://898807]
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found