Prev: Copy entire directory
Next: C# projects
From: Sharon on 27 Jun 2010 03:02 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? ------- Thanks Sharon
From: Willem van Rumpt on 27 Jun 2010 04:00 On 27-6-2010 9:02, Sharon wrote: > 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. -- Willem van Rumpt
From: Mr. Arnold on 27 Jun 2010 04:33 Sharon wrote: > 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
From: Peter Duniho on 27 Jun 2010 04:34 Sharon wrote: > 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? In general, unless you're using an established, RFC-supported protocol, you'll want to choose a port number between 5000 and 49151. Unfortunately, even in that range there is the possibility of a conflict. Ultimately, you'll want to design your program so that the port # is configurable. Even software using the established protocols, such as HTTP, NNTP, FTP, POP, SMTP, etc. follow this convention. It's just a good idea, at least in part because port # conflicts are common (for the established protocols, it's more about being flexible in case of firewall issues or wanting to run multiple servers on the same computer). See http://tangentsoft.net/wskfaq/intermediate.html#svrport for more details. Pete
From: Sharon on 27 Jun 2010 05:58
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. ------- Thanks Sharon "Mr. Arnold" wrote: > Sharon wrote: > > 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 |