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


In reply to Multiple consecutive connections to a socket (probably a stupid question) by vr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.