carlin has asked for the wisdom of the Perl Monks concerning the following question:
writer.pl#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $socket = new IO::Socket::INET( LocalHost => '127.0.0.1', LocalPort => 7070, Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket\n" unless $socket; while( 1 ) { my $input = $socket->accept(); print <$input> ."\n"; close( $input ); }
Removing the print statement in reader.pl fixes this, but replacing print with sleep(1) doesn't make it occur (I thought the slight delay in making it print must have been blocking).#!/usr/bin/perl use strict; use warnings; use IO::Socket; sub makeSock { my $socket = new IO::Socket::INET( PeerAddr => 'localhost', PeerPort => 7070, Proto => 'tcp', ); die "Could not connect\n" unless $socket; return $socket; } my $i = 1; while( 1 ) { my $socket = makeSock(); print $socket $i; close( $socket ); $i++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket disconnects in loop
by ikegami (Patriarch) on Jun 13, 2009 at 19:48 UTC | |
by carlin (Beadle) on Jun 14, 2009 at 04:06 UTC | |
by ikegami (Patriarch) on Jun 14, 2009 at 07:57 UTC | |
|
Re: IO::Socket disconnects in loop
by Perlbotics (Archbishop) on Jun 13, 2009 at 19:52 UTC | |
by carlin (Beadle) on Jun 14, 2009 at 04:13 UTC |