Yesterday when I was working on Re: Problems with select() on socket, I used this piece of code to test against it: (I am using win98 + Perl 5.8.0)

use IO::Socket::INET; use IO::Select; use strict; use warnings; my @sockets; my $select = new IO::Select(); my $packet_rcvd; for ($ARGV[0] .. $ARGV[1]) { my $socket = new IO::Socket::INET(Proto => "udp", LocalPort => $_, + LocalAddr => "localhost") || die "failed to establish socket for por +t $_"; print "udp socket created for port $_\n"; $select->add($socket); } print "all socket created\n"; while (1) { my @sockets = $select->can_read(10); for my $socket (@sockets) { my $peer = $socket->recv($packet_rcvd, 50); print "packet $packet_rcvd recvd at port " . $socket->sockport +() . "\n"; $socket->send("abcdefg", 0, $peer); } print $select->count(), "\n"; }

But I noticed that, if I have more than 64 ports open, only the first 64 ports actually receive packets, and response.

The script didn't die on socket establishment, so seems ports really got opened, (or failed but Perl didn't report?).

This is a per process limitation, if I run two instances of this script, each will have 64 ports response properly.

This is probably even not a Perl issue (OS?). How can I increase number of open ports allowed (on win98)?

Update:

The passage BrowserUK found explains this.

Changed the way of using select, and tried with this piece of code:

use IO::Socket::INET; use IO::Select; use strict; use warnings; my @sockets; my $packet_rcvd; for (4000 .. 4200) { my $socket = new IO::Socket::INET(Proto => "udp", LocalPort => $_, + LocalAddr => "localhost") || die "failed to establish socket for por +t $_"; print "udp socket created for port $_\n"; push @sockets, $socket; } print "all socket created\n"; for my $socket (@sockets) { my $select = new IO::Select($socket);#now select is only for one s +ocket, obviously less than 64 my @readable; do { @readable = $select->can_read(1); } until ($#readable != -1); my $peer = $socket->recv($packet_rcvd, 50); print "packet $packet_rcvd recvd at port " . $socket->sockport() . + "\n"; }

Now 125 ports responsed. But this 125 again seems to be some sort of limit.

Any way, if one wants to get around the 125 limitation, can just go multi-process.

select is obviously part of the problem for 64 limit. The first part in the passage provided by BrowserUK cannot be independently tested, as the implementation might not even use those mentioned function calls underneath.


In reply to maximum number of open ports per process on win98 by pg

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.