Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: No data received on client socket

by rbi (Monk)
on Sep 19, 2006 at 17:24 UTC ( #573773=note: print w/ replies, xml ) Need Help??


in reply to Re: No data received on client socket
in thread No data received on client socket

I've tried it, but it does not work.
By the way, on old installations it works with recv().
I've read that recv() shrinks to a smaller size if the last chunk of bytes is shorter than the specivfied size (4096 in this case), while sysread tries to read the specified size.

Update I've tested your implementation and - as with the original code - I can see with tcpdump the query results coming back as network traffic but I get nothing in Perl.


Comment on Re^2: No data received on client socket
Re^3: No data received on client socket
by ikegami (Pope) on Sep 19, 2006 at 18:27 UTC
    Does the server close the socket after the response is sent? My code assumed so. The following looks for </xml> instead.
    # Receive response. my $read_buf = ""; my $response; for (;;) { my $rv = sysread($oSocket, $read_buf, 4096, length($read_buf)); die("Unable to read from the socket: $!\n") if not defined $rv; die("Premature end of data\n") if not $rv; if ($read_buf =~ s{(.*</xml>)}{}si) { $response = $1; last; } }

    Tested. Both version work fine for me (although the first requires that the server closes the socket after sending the response).

    I've read that recv shrinks to a smaller size if the last chunk of bytes is shorter than the specivfied size (4096 in this case), while sysread tries to read the specified size.

    sysread is never guaranteed to return the number of bytes requested. When reading from a socket, it returns when LENGTH bytes are available and after each (non-empty?) packet received. And left-over bytes are returned by the next call to sysread.

    By the way, Type => 'SOCK_STREAM' should be Type => SOCK_STREAM, and specifying both Type and Proto is redundant.

      Thank you very much for all this, but I still don't get anything ("Premature end of data" from your code).
      I'm ignorant - among other things :) - about sockets. I thought it could be something not depending from the Perl script istself but from something at "lower level" since the script works just the same on other older Linux computers. Also, on this new Linux computer the access to the same database with the same test query works with a php implementation, as I've just found out.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2014-08-31 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls