Reading a single line from a socket 
Author Message
 Reading a single line from a socket


Quote:
> Try making your pipes hot.  This is a helpful idiom:

> $oldfh = select(S); $| = 1; select($oldfh);

> There is a very helpful article on making pipes autoflush "hot" in last
> month's Perl Journal, check it out.

The English name of the $| special variable is $OUTPUT_AUTOFLUSH.

I don't expect that setting it to 1 will be much help when using the
filehandle for *input*.

The best way to return only the first line is to read only the first
line.

print scalar <S>;

Beyond that, four-argument select() is called for.
(Or the IO::Select module.)

Quote:

> > The server spits out a greeting, and then waits for user input...much
> > like SMTP.  What I need to do is write a small testing script that will
> > connect to the port and return only the first line.
> > I have tried using:

> > while(<S>) {
> >   print;
> > }

> > ...but that hangs b/c the server is awaiting for user input.

--


    /                                   http://www.*-*-*.com/ ~rjk/
        "It's funny 'cause it's true ... and vice versa."


Sat, 21 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Reading a single line from a socket

2. Single character reads on sockets

3. Single character reads on sockets

4. How to read single line from file?

5. Sorting multiple-line data to single line data

6. I want to convert a mutli-line list to a single line

7. single line regex and multi-line regex without resetting $/

8. QUESTION: rewriting a single line as several shorter lines

9. read last line without reading previous lines, how?

10. reading line from socket

11. request help to read one line from tcp socket into mysql

12. Sending single byte over IO::Socket

 

 
Powered by phpBB® Forum Software