cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Bros. I have written the following socket client to communicate with a parser running on another machine on my LAN:
It works in the sense that it sends the sentence to the parser and prints the parser's response correctly; however, after the parser output is complete the script doesn't terminate. I guess it's caught in the while loop, though it doesn't seem to be printing blank lines or anything.#!/usr/bin/perl -w use strict; use IO::Socket::INET; $| = 1; my $socket = new IO::Socket::INET ( PeerHost => '192.168.1.107', PeerPort => '27109', Proto => 'tcp' ) or die "No socket: $!\n"; my $sent = 'This is a test.'; print $socket "$sent\n\n"; while(<$socket>) { print "$_"; } $socket->close();
I have tried changing the while loop to
but I get the same behavior. What am I doing wrong?my $line; while( defined($line=<$socket>)) { print $line; }
Thanks,
Steve
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Why won't this socket client terminate?
by BrowserUk (Patriarch) on Jul 09, 2011 at 21:34 UTC | |
Re: Why won't this socket client terminate?
by Marshall (Canon) on Jul 10, 2011 at 07:48 UTC | |
by cormanaz (Deacon) on Jul 10, 2011 at 15:12 UTC | |
by Marshall (Canon) on Jul 10, 2011 at 15:46 UTC | |
by cormanaz (Deacon) on Aug 06, 2011 at 20:47 UTC | |
Re: Why won't this socket client terminate?
by Khen1950fx (Canon) on Jul 10, 2011 at 05:43 UTC |
Back to
Seekers of Perl Wisdom