Re: Maximum sockets
From: Phil Frisbie, Jr. (phil_at_hawksoft.com)
Date: 02/09/05
- Next message: Alun Jones [MSFT]: "Re: Extra events on sockets???"
- Previous message: Chad: "Maximum sockets"
- In reply to: Chad: "Maximum sockets"
- Next in thread: Michael K. O'Neill: "Re: Maximum sockets"
- Reply: Michael K. O'Neill: "Re: Maximum sockets"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 09 Feb 2005 15:45:33 -0800
Chad wrote:
> Essentially, my question is this:
I already saw this multiposted to another group earlier, but I guess I can
answer it here now that I have the time...
> What is the maximum number of sockets allowed (in any
> state, ie:
> ESTABLISHED, CLOSE_WAIT, FIN_WAIT_2, etc) per thread? per
> process?
> globally?
There is no hard coded limit on NT based OSs. However...
> The reason for this question is that a client application
> that I wrote,
> which makes many separate and short connections to a server,
> occasionally receives a WSAEADDRINUSE error message after
> attempting a
> connect(). As I understand it, this message must be
> arising because a
> local port that my socket is binding to is already being
> used. Since I
> tell Windows to allocate the port itself, this should never
> happen.
This is not a socket problem, it is a port problem.
> Looking at one "netstat" snapshot during runtime, I notice
> that there
> are approximately 377 sockets in use globally, and my
> application is
> using 270 sockets (20 of those 270 sockets are in an
> ESTABLISHED state,
> the rest are in a CLOSE_WAIT state).
Yes, you found your problem, even if you did not understand that answer! When
you call connect() Windows assigns it to a unused port. The problem is that by
default Windows only uses the ports from 1024 through 5000. When you close a TCP
socket, it stays in the CLOSE_WAIT for about two minutes, so you can only
connect and close less than 3976 sockets every two minutes.
> I am wondering if 270 sockets per process is a maximum for
> Windows 2000
> Professional. If that is so, then when I perform a
> connect(), Windows
> might be unable to grant additional sockets, so it must grant a
> pre-existing socket (which is where the WSAEADDRINUSE
> message is coming
> from). At least, this is my theory. I hope somebody has
> some actual
> evidence of any socket limits.
You can connect more than 8000 sockets on Windows 2000 Pro with 256 MB of RAM,
you just need to get around the 'port 1024 through 5000' limitation Windows uses.
You can either make a registry change. A news group search will turn up that
info, or you can use a socket library that bypasses the limitation. I have one
on my website below that if free to use, or you can just see how I did it and
write your own code.
> It has been difficult to find relevant answers to this
> question, as
> most descriptions of the WSAEADDRINUSE error message
> describe servers
> that are listening on a port already in use. In my case,
> Windows
> should be automatically choosing a free port, and
> apparantly it is not.
The 'magic' phrase is 'ephemeral port range'.
> Any help would be greatly appreciated.
-- Phil Frisbie, Jr. Hawk Software http://www.hawksoft.com
- Next message: Alun Jones [MSFT]: "Re: Extra events on sockets???"
- Previous message: Chad: "Maximum sockets"
- In reply to: Chad: "Maximum sockets"
- Next in thread: Michael K. O'Neill: "Re: Maximum sockets"
- Reply: Michael K. O'Neill: "Re: Maximum sockets"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|