I’m working on a server application and I want to open a lot of ports. What is the maximum number of ports I can open and a windows machine? Thanks!
EDIT: What I mean is how many ports can I open for listening (as a server)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What most people aren’t explaining to you barring the one comment by tsells is that most likely you have an invalid assumption of how tcp stacks typically work (This was actually something I got confused with until not too long ago).
The reason is that when you have a TcpListener (Specific to DotNet but probably applicable to most other tcp libraries) is that when you begin listening and an incoming connection takes place the stack will listen on a port of your choosing (eg: Port: 1234) but once connected will move the connection to a (typically) random unassigned port.
So for example looking at the following code.
What this basically means is that unless you’ve got a VERY GOOD reason you shouldn’t really care about these implementational details and the maximum open ports is fundamentally irrelevant (Also good luck trying to write something that spawns 30000 threads and maintains those connections correctly and efficiently).
PS: I have also verified inside of the System.Net.Sockets.TcpListener when a port number is provided the following code is called and will throw a ArgumentOutOfRangeException if it fails this test. This confirms what ‘Igby Largeman’ said in that it is a 16 bit unsigned integer.