"Too many open files - socket(2)" when invoking Socket.new

C

Clemens Wyss

Given the follwing code snippet:

require 'socket'
include Socket::Constants
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 1313, 'localhost' )
socket.bind( sockaddr )
socket.listen( 5 )
client, client_sockaddr = socket.accept
client.puts "Hello from script one!"
puts "The client said, '#{client.readline.chomp}'"
client.puts "Hello from script one!"
socket.close

On my WinXP development machine this script runs as expected. Running it
on a WinXpEmbedded machine throws a
Too many open files - socket(2) (Errno::EMFILE)
exception on the line
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
What could cause this exception?

Any advice help appreciated
Clemens
 
S

Sandor Szücs

Given the follwing code snippet:


require 'socket'
include Socket::Constants begin

socket =3D Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr =3D Socket.pack_sockaddr_in( 1313, 'localhost' )
socket.bind( sockaddr )
socket.listen( 5 )
client, client_sockaddr =3D socket.accept
client.puts "Hello from script one!"
puts "The client said, '#{client.readline.chomp}'"
client.puts "Hello from script one!" ensure

socket.close
end


Try to add these statements in your code and reboot your box,
then it should not happen.
On my WinXP development machine this script runs as expected. =20
Running it
on a WinXpEmbedded machine throws a
Too many open files - socket(2) (Errno::EMFILE)
exception on the line
socket =3D Socket.new( AF_INET, SOCK_STREAM, 0 )
What could cause this exception?


Too many open files for your OS results in such an exception.

regards, Sandor Sz=FCcs
--=
 
C

Clemens Wyss

Dear Sandor,
I don't see why your exception handling code should be of any help. The
exception per se is the problem.

Why (on XP embedded only) do I get
Too many open files - socket(2) (Errno::EMFILE)
on the line
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
?
Also: opening the very same port with a simple VB App works, even on XP
embedded...

Still any help/advice appreciated
Clemens
 
S

Sandor Szücs

I don't see why your exception handling code should be of any help. =20=
The
exception per se is the problem.

True, but I thought if you try to run your code and it doesn't close =20
the sockets,
then you get open files.... It's better to ensure the close operation.

regards, Sandor Sz=FCcs
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top