pg has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: maximum number of open ports per process on win98
by BrowserUk (Patriarch) on Nov 27, 2003 at 04:47 UTC | |
|
Re: maximum number of open ports per process on win98
by noslenj123 (Scribe) on Nov 27, 2003 at 18:05 UTC | |
by Anonymous Monk on Nov 28, 2003 at 23:31 UTC |