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

Can I read a line from a socket without the socket sending \n?

by reyjrar (Hermit)
on Nov 30, 2000 at 20:56 UTC ( [id://44171]=perlquestion: print w/replies, xml ) Need Help??

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

  • Comment on Can I read a line from a socket without the socket sending \n?

Replies are listed 'Best First'.
Re: Can I read a line from a socket without the socket sending \n?
by mikeock (Hermit) on Nov 04, 2005 at 15:56 UTC

    I use a socket connection in a subroutine that closes after I send a command. The easiest way that I have found to read the text back is using the shutdown ($socket_name, 1). You can then run a

    while(<$socket_name>){ print $_; }
    to return whatever the prompt/responce is.

    Again, for each command that I send, I create a new socket connection send the command and disconnect/kill the socket.

    Also once the while loop is in place, you can use a regex to take what you want out, like the prompt, since it is making a new connection everytime.

Re: Can I read a line from a socket without the socket sending \n?
by merlyn (Sage) on Nov 30, 2000 at 21:09 UTC
    The hardest part about sockets is knowing when to stop reading. You can invent a line-oriented protocol, or use some other indication (like a byte count followed by that many bytes).

    Knowing what to use is an art call, decided by experience and study of the prior art. Good luck in your quest!

Re: Can I read a line from a socket without the socket sending \n?
by crazyinsomniac (Prior) on Dec 10, 2000 at 03:24 UTC
    Ok ask your self this,
    what is a line?
    if you can answer it without using '\n' then you can read a line without sending '\n'.
    If i were you i would seriously consider limiting the length of a line to 80 characters,
    that way when you just read 80 chars you consider it a line or just stick to what works and send '\n'.
Re: Can I read a line from a socket without the socket sending \n?
by Anonymous Monk on Dec 06, 2000 at 18:07 UTC
    use sysread
Re: Can I read a line from a socket without the socket sending \n?
by Anonymous Monk on Oct 22, 2004 at 19:03 UTC
    hi rleroy@avantages.com

    Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-25 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found