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

Read Socket data on data, not return

by ecuguru (Monk)
on Dec 22, 2004 at 09:12 UTC ( #416727=perlquestion: print w/ replies, xml ) Need Help??
ecuguru has asked for the wisdom of the Perl Monks concerning the following question:

I've been ripping off some terrificly straightforward code on multithreaded servers from Brian Slesinsky here .
The code snippet that I'm playing with is this:
$socket->recv($line,10); Anyone know how I can make that line of code move on based on buffer size rather then waiting for the carriage return? Or any other way of looking at the data without needing to wait for a carriage return?

So when I make a socket connection to the server, I have to make a carriage return to get the next line moving. I'm playing with a socket that will only send data and no carriage returns, and I don't see any of the data until the device disconnects <no good>..

And although I understand the second integer parameter to be the max size of the line, I don't understand what affect it has on the code. I changed it to 5 bytes, thinking perhaps it was a length interrupt and I could check it that way. But changing the value didn't seem to do anything.

Comment on Read Socket data on data, not return
Download Code
Re: Read Socket data on data, not return
by steves (Curate) on Dec 22, 2004 at 09:40 UTC

    It seems more likely that the server you're connecting to is not actually sending the data until a carriage return is issued there. In other words, no matter how your client tries to read the data, it can only get anything if the server has actually written a packet to the socket. Depending on how the socket is being used in the server, the data may be buffered and may not actually be written to the underlying socket until a carriage return is issued.

    Can you post some example server code?

      The entire server working code is in the first link: here
      I'm only using telnet as the client, which is sending in every character.
      client = telnet localhost 2323

      thanks!!

        Does your local telnet client tell you it's operating in character and not line mode? telnet can operate in either. I find that when I connect to non-telnet servers, my telnet client is in line mode, which would explain why your server is "waiting" for newlines -- it's actually only seeing full lines from the client, not characters. To see your telnet client's current mode, escape into telnet command mode and issue the status command.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-07-24 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls