Because of examples in documentation (while ( accept ... etc. ), I thought that an IO::Socket::INET object can be used to accept many connections with different clients, consecutively. However, this client-server example halts (hangs) trying to accept the 65th client.
# server use strict; use warnings; use IO::Socket::INET; STDOUT-> autoflush( 1 ); my $external = 'external.pl'; my $sock = IO::Socket::INET-> new( LocalHost => '127.0.0.1', LocalPort => 5001, Proto => 'tcp', Listen => 5, Reuse => 1 ) or die; for ( my $i = 1;; $i ++ ) { print "# $i "; system 1, $^X, $external, $i; print ' accepting... '; my $client = $sock-> accept; print 'reading... ', <$client>; $sock-> shutdown( 2 ); $client-> close; sleep 1 }
And "a client" (i.e. 'external.pl'):
# client use strict; use warnings; use IO::Socket::INET; my $sock = new IO::Socket::INET ( PeerHost => '127.0.0.1', PeerPort => 5001, Proto => 'tcp', ) or die; print $sock "$ARGV[ 0 ]\n"; $sock-> close;
The magic "computeresqe" nature of the "64" number (remaining the same when sleeping for 3, rather than 1) makes me think, the solution is very close, I'm just missing something. But, I can't figure out what.
Perl is e.g. Strawberry 5.020 Win32
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |