Chossing port for server lsitening

S

Sharon

I’m writing a server that listen for client connections.
I chose the 2902 port. But today I received a SocketException as follow:
Message: Only one usage of each socket address (protocol/network
address/port) is normally permitted
Method: Socket.DoBind

I examined the netstat output and found that some other process has an
established connection on this same port.

My question is:
What is the range of ports numbers that I can use for my server to listen
on, and making sure the Windows OS will not use them?
 
W

Willem van Rumpt

I’m writing a server that listen for client connections.
I chose the 2902 port. But today I received a SocketException as follow:
Message: Only one usage of each socket address (protocol/network
address/port) is normally permitted
Method: Socket.DoBind

I examined the netstat output and found that some other process has an
established connection on this same port.

My question is:
What is the range of ports numbers that I can use for my server to listen
on, and making sure the Windows OS will not use them?

Strictly speaking, you could choose any port you like. The range of 0
until 1023 however are known as the well-known- ports, and should not be
used, unless you're writing a server that wants to perform the task it
was intented for.

Above 1023, there's a whole range of registered ports: Ports that are
known to be used by specific software and/or technologies, but you can
basically choose whatever number you want.

The best way to solve your problem, is to make the port for your server
configurable. That way, you can always avoid conflicts. Even more, if
the application is to be delivered to customers, you'll have no choice
but to make it configurable. You simply can't assume that there's
nothing listening on a specific port already.
 
M

Mr. Arnold

Sharon said:
I’m writing a server that listen for client connections.
I chose the 2902 port. But today I received a SocketException as follow:
Message: Only one usage of each socket address (protocol/network
address/port) is normally permitted
Method: Socket.DoBind

I examined the netstat output and found that some other process has an
established connection on this same port.

My question is:
What is the range of ports numbers that I can use for my server to listen
on, and making sure the Windows OS will not use them?

You can use any high port above 1024 to 66535, as long as the port is
not being used by another application that's running on the machine,
like SQL server is listening TCP port 1433.

So if SQL Server is running on the machine, you can't use that port. But
if SQL server is not running on the machine, then you can use the port.

But the rule of thumb is you don't use 1433 and avoid it, leaving it for
the possibility that SQL Server could be installed on the machine.
It's just an example of the decision making process you must use in
choosing a port to be used by your application.

http://www.iana.org/assignments/port-numbers
 
S

Sharon

Hi Arnold,
As you can see on my post, I’m using port number above 1023 which is 2902.
And the process/application that already took this port received this port
from the Windows OS dynamically while connecting to some other remote server.
I need to make sure that Windows won’t take the port I wish to listen on.

You can assume that computer is a dedicated PC that does not have any
application/server which is configured to this same port. SO the only way
this port can be taken, is by the Windows OS (WinXP).

So I do need to know the range of port that I can listen so they will not be
taken/given by the OS.


Willem – I am using a configuration file for the listening port. But
changing it is not easy as it controlled by authorization system and many
clients are connecting to this known port.
 
M

Mr. Arnold

Sharon said:
Hi Arnold,
As you can see on my post, I’m using port number above 1023 which is 2902.
And the process/application that already took this port received this port
from the Windows OS dynamically while connecting to some other remote server.
I need to make sure that Windows won’t take the port I wish to listen on.

It didn't take that port dynamically.

2902/tcp NET ASPI is a reserved high port, like 1433 is a reserved high
port for SQL Server.
You can assume that computer is a dedicated PC that does not have any
application/server which is configured to this same port. SO the only way
this port can be taken, is by the Windows OS (WinXP).

So I do need to know the range of port that I can listen so they will not be
taken/given by the OS.

I suggest you look at the port assignments for 'reserved high ports'
above 1024 in the link I gave you and use a port that's past the
'reserved high ports list'.

But it's still contingent upon you knowing that a high port past the
'reserved ports list' is NOT being used by a 3rd party vendor's software
or another devloper in-house that has not written an application
listening running on the port you have chosen. It's just general principle.

http://www.iana.org/assignments/port-numbers
 

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

Top