Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Perl's IO::Socket on Windows complain about "Resource Not Available" after 64 connections?
    primarykey
    data
    text
    <p>I created a server with Perl under Windows (ActivePerl 5.10.1 build 1006) that forks upon being connected to, accepts some JSON data, and writes it to a database. I am running into a problem after 64 clients connect to the server, the error message being "Resource is not available" when trying to fork.</p> <p>Running this code under Linux I found many defunct child process, which was solved by adding a <code>wait()</code> call on the parent. This however did not solve the problem. Running the code under Linux works past the 64 calls allowed in Windows.</p> <p>I also spun up a virtual Windows server in case it was restrictions on the server, but a fresh install of Perl resulted in the same 64 connection limit.</p> <p>Any ideas is appreciated.</p> <pre><code> use IO::Socket; use Net::hostent; use JSON; use DBI; use Data::Dumper; my $port=shift || 9000; my $clients_served = 0; while(1){ my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Listen => 1, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 is running]\n"; #### # wait for a client to connect # once it has, fork to a seperate thread and # retrieve the JSON data #### while (my $client = $server->accept()) { my $pid = fork(); if ($pid != 0) { print ("Serving client " . $clients_served++ . "\n"); }else{ $client->autoflush(1); my $JSONObject = JSON->new->ascii->pretty->allow_nonref(); my $hostinfo = gethostbyaddr($client->peeraddr); my $client_hostname = ($hostinfo->name || $client->peerhost); printf "connect from %s\n", $client_hostname; print " $client_hostname connected..\n"; syswrite($client, "Reached Server\n", 2048); if (sysread($client, my $buffer, 2048) > 0) { foreach my $tasks($JSONObject->decode($buffer)){ foreach my $task (@$tasks){ insert_record($client_hostname, $task); #empty method, contents does not affect result } } } print " $client_hostname disconnected..\n"; close $client; exit 0; } } $server->close(); } exit 0; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload