Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Problem Transmitting Data via TCP/IP

by scorpio17 (Monsignor)
on Aug 09, 2012 at 20:12 UTC ( #986601=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Problem Transmitting Data via TCP/IP
in thread Problem Transmitting Data via TCP/IP

Thanks again. I've never taken the time to learn how pack and unpack work as well as I should, and it looks like that mistake has finally caught up with me.

For what it's worth - the original C++ code (which I didn't write) used the functions htonl() and ntohl(). I was not familiar with those, but could tell that it had something to do with encoding/decoding data, so I googled for a perl implementation, and found one in the Net::Inet module on CPAN. It's written to take an array of inputs, but I knew that in my case I'd only be sending in a single argument.

As it turns out, my code did have another error: recv() returns undef if there's an error, so I had to change this:

# this is broken !!! $socket->recv($data, $reponse_length) or die "Couldn't read data from +server: $!";

into this:

unless (defined $socket->recv($data, $reponse_length)) { die "Couldn't read data from server: $!"; }

But everything seems to be working now -thank you!!


Comment on Re^4: Problem Transmitting Data via TCP/IP
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (17)
As of 2015-07-29 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls