Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Can't display last line with IO::Socket::INET

by swkronenfeld (Hermit)
on Jan 20, 2005 at 06:24 UTC ( [id://423612]=perlquestion: print w/replies, xml ) Need Help??

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

I have an extremely basic telnet program in perl as follows
#!/s/std/bin/perl -w use strict; use IO::Socket::INET; if(@ARGV != 1) { die("usage: client.pl host:socket\n") } my $sock = new IO::Socket::INET("$ARGV[0]") or die("Couldnt connect: $ +!"); my $pid = fork(); if($pid == 0) { #$|++; while(<$sock>) { print $_; } } else{ while(<STDIN>) { print $sock $_ } } close($sock);
The problem is, the last line of text received from the server is a prompt which doesn't contain a line break. This line doesn't get displayed until after I provide my input. So my output might look something like this...
Connecting to xxx ls** home$ public private somefile ...
The ls is my input, the home$ is the missing prompt, appearing before the file listing.

I thought at first that this was a problem with autoflush, but when I added the above $|++ line to STDOUT (which is what I *think* I'm doing, I also tried STDOUT->autoflush(1);), it didn't fix anything. I attempted to manually print a line break immediately following any output received from the server (which isn't my desired behavior), but that just adds line breaks after every single line, and still doesn't display the last line.

Does anyone have any advice for this problem? I'm not really sure where to go, I tried reading about sockets, but there's a ton of information, and there's nothing regarding this kind of thing in the CPAN info on this module.

Replies are listed 'Best First'.
Re: Can't display last line with IO::Socket::INET (read)
by tye (Sage) on Jan 20, 2005 at 14:21 UTC
Re: Can't display last line with IO::Socket::INET
by dave_the_m (Monsignor) on Jan 20, 2005 at 14:16 UTC
    You are using  <> to read complete lines from a socket. If you only want to read partial lines, then then you'll need a different approach, most likely involving sysread()

    Dave.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-03-28 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found