Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

extremeperl · Extreme Perl

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 344
  • Category: Software
  • Founded: Jan 27, 2002
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

Advanced
Messages Help
IO::Socket:INET Client problem   Topic List   < Prev Topic  |  Next Topic >
Summarize Messages | View Threaded Sort by Date v  
#56 From: Tom Brown <tbrown@...>
Date: Mon Dec 23, 2002 7:02 pm
Subject: Re: IO::Socket:INET Client problem
tbrown@...
Send Email Send Email
 

I think Rob's answer was backwards... e.g. the read side of things, not
the write (print) side of things, but it isn't very clear where
the problem lies. His answer is quite correct <> isn't the normal
way to grab data from a socket... it is meant for line oriented
input...

I think you're just looking for

my $old = select $socket;
$| = 1;
select $old;

which changes the filehandle to no longer be buffered. You may
need to run it for STDOUT too.

-Tom



On Mon, 23 Dec 2002, diarmuid_obriain <diarmuid_obriain@...> wrote:

> I have a problem with a TCP Client I am working with. It works fine
> if the data on the server that is being sent to the socket has
> a '\r\n' at the end of the line however if it does not then that line
> is not printed until after the next \r\n action. This basically makes
> it impossible for the client to see a command prompt from the server
> which would naturally not have the \r\n at the end of the line. Is
> there any way in Perl of forcing the client to print the contents of
> the buffer without waiting for the \r\n sequence.




#55 From: "diarmuid_obriain <diarmuid_obriain@...>" <diarmuid_obriain@...>
Date: Mon Dec 23, 2002 6:13 pm
Subject: Re: IO::Socket:INET Client problem
diarmuid_obr...
Send Email Send Email
 
Rob,

Thanks,

I tried this but it still doesn't work.

Diarmuid





#54 From: Rob Nagler <nagler@...>
Date: Mon Dec 23, 2002 5:44 pm
Subject: Re: IO::Socket:INET Client problem
robnagler
Send Email Send Email
 
"diarmuid_obriain <diarmuid_obriain@...>" <diarmuid_obriain@...>
writes:
> while ($element = <$socket>) {
> print STDOUT "$element";
> }

This isn't the right list for this type of question, but I'll respond
anyway:

while (sysread($socket, $element, 8192)) {
print STDOUT $element;
}

The readline (<>) function stops reading a \n. There's no way around
this by definition.

Try http://www.perlmonks.org for questions like this in the future.

Cheers,
Rob





#53 From: "diarmuid_obriain <diarmuid_obriain@...>" <diarmuid_obriain@...>
Date: Mon Dec 23, 2002 4:31 pm
Subject: IO::Socket:INET Client problem
diarmuid_obr...
Send Email Send Email
 
I have a problem with a TCP Client I am working with. It works fine
if the data on the server that is being sent to the socket has
a '\r\n' at the end of the line however if it does not then that line
is not printed until after the next \r\n action. This basically makes
it impossible for the client to see a command prompt from the server
which would naturally not have the \r\n at the end of the line. Is
there any way in Perl of forcing the client to print the contents of
the buffer without waiting for the \r\n sequence.

Here is the client I am working with.


Any help appreciated.

Diarmuid

---------------------- tcpClient.pl -------------------------

#!/usr/bin/perl -w

use strict;
use IO::Socket;
my ($program, $server, $port, $forkchild, $socket, $element);

if ($0 =~ /.*\/(\S+?)$/){
$program = $1;
}else{
$program = $0;
}

unless (@ARGV == 2){
die "\r\nusage: $0 <host> <port>\r\n\r\n";
}else{
($server, $port) = @ARGV;
}

$socket = IO::Socket::INET->new(Proto => 'tcp',
PeerAddr => $server,
PeerPort => $port)
or die "cannot connect : $|";

print "\r\n[Connected to $server:$port]\r\n";

print "\r\nFork failed: $!\r\n\r\n" unless (defined ($forkchild = fork
()));

if ($forkchild){
while ($element = <$socket>) {
print STDOUT "$element";
}
kill("TERM", $forkchild);

}else{
while ($element = <STDIN>) {
print $socket "$element";
}
}

---------------------------------------------------------------------




 
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help