Search code examples
windowsipcports

IPC port ranges


IPC can be done via TCP/IP sockets. Which port ranges should I use for local IPC between programs under windows?
Does it matter which Windows version I'm using?
In case I'd like to be cross-platform compatible, is it any different under Linux?
Does it matter what language I write in?
Does it matter if the IPC is local or not?


Solution

  • In principle, if your program is going to be used widely, you should get a port number assigned to you by IANA as per RFC6335. If you don't qualify for an assignment your program should choose an unused port in the 49152-65535 range at run-time and communicate this port number to the other processes by some other means.

    In practice, you can usually get away with using any infrequently-used port in the range 1024-49151, although you should allow for the possibility that another program will be using it. Typically this is done by allowing the user to configure use of a different port, e.g., you could use a registry setting.

    Assigned port numbers can be viewed at IANA. This list may be helpful in avoiding ports that are particularly likely to be in use.

    For the record, on Windows it is usually simpler to use some other IPC method such as named pipes.