Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose which port to use when building a windows service? (windows & .net) [closed]

I'm writing a windows service which will expose an http RESTful web service for other processes on the machine. This will be deployed to lots of machines on various corporate desktops that I have little/no control over. How should I choose which port my service should listen on?

I'll make it configurable, but need to know how to choose some reasonable default(s).

fyi I'm planning on using .NET 3.5 (unable to use 4.0 for deployment reasons) and WCF with WCF REST Starter Toolkit.

UPDATE: to clarify, these are corporate non-development machines. I want to choose a port that's not likely to be used for anything else. I guess from this list of PORT NUMBERS (thanks @Pascal Thivent) that I should choose one in the dynamic/private range

The Dynamic and/or Private Ports are those from 49152 through 65535

So is there any better way of choosing a port within that range, or do I just choose randomly?

like image 962
Rory Avatar asked Sep 26 '10 22:09

Rory


People also ask

What port should I use for my service?

If your service is HTTP then you should use port 80 - the standard HTTP port. This is typical of most REST webservices.

How do I assign a service to a port?

The algorithm used for assigning a port to each service works as follows: 1) The project's name is hashed. 2) The hash absolute value is projected on the port range (the default port range is [20000,30000] ). 3) The selected port is assigned to the project, if there is no other project claiming the same port.

How do I know which port to use?

Type “netstat -a” without the quotation marks and press the “Enter” key. A list of data appears. The first column signifies the protocol type used, while the second column displays a list of local connections that are in use. The number that appears after the colon in this column is the port that is in use.

Can we change default port for a service?

Changing the port that a service uses depends heavily on the service. For example, you can set HTTP's port with the Internet Service Manager (ISM). Change 161 and 162 to the ports you want to use, and save the file. You must restart the computer for the change to take effect.


1 Answers

The official assignments registred with the Internet Assigned Numbers Authority (IANA) for HTTP are:

  • 80: standard port for HTTP,
  • 8080: HTTP alternate (commonly used by cache or proxy or web server running as a non-root user)

The ports below are non official ports (not registered with IANA) that are also used:

  • 8081: HTTP alternate
  • 8090: HTTP alternate (used as an alternative to port 8080)

I don't know what kind of machines you are targeting but if they include development machines, I would probably use 8090 to minimize possible conflicts.

References

  • PORT NUMBERS
  • List of TCP and UDP port numbers
like image 191
Pascal Thivent Avatar answered Sep 19 '22 01:09

Pascal Thivent