views:

413

answers:

3

How many is the maximum number of sockets in java under windows? How can I change it?

+1  A: 

The theoretical maximum is 65535, since a 16-bit number is used to store the port number in the TCP/IP packet, and port 0 is not usable. The practical limit will be lower since a number of ports will already be in use by the system.

Ignacio Vazquez-Abrams
A server socket listens on one port and serves many remote clients (with a unique remote addr/remote port pair), you don't run into the 16 bit limit in that case.
nos
For example in linux you can have only 1024 fds. what about windows and java?
Shayan
1024 is just a common soft limit on many distros, it can be changed.
nos
@Ignacio: That is wrong, since one port can be used for multiple TCP connections, both inbound and outbound.
jarnbjo
+1  A: 

This is largely dependent on the max number of file descriptors (handles in Windows) the OS is configured for. Each open file or socket uses one file descriptor. In Solaris, for example, 65536 is the default for max fd's. Chances are, there are additional files using the pool of FD's, therefore limiting the upper limit of sockets unless the OS is tuned to increase the number of FD's

In Windows NT/2000/XP (Probably Vista & 7) there should be an entry "FILES=" in \Windows\System32\config.nt (Possibly also a registry setting?) that should give you the max number of file handles.

Here is a more in depth discussion of the limits in Windows:

http://blogs.technet.com/markrussinovich/archive/2009/09/29/3283844.aspx

Steve
+1  A: 

It depends on the configuration of your Windows installation. I don't think that Windows has a process specific limit on the number of TCP connections, but there is a system wide configuration in the registry. You can find an article here, in which the registry keys are described.

jarnbjo