开发者

Which port can i use for my socket?

Hello I am a beginner and i want to know how I can decide which port I can use for my socket开发者_运维问答?

Thanks.


You can use any port that is not already used by any application.
I suggest to stay away from 1-1024 ports.These ports are used by common applications.
Here is a list of app's and what ports they are using : List


For best practice you should your ports in the range of 49152-65534

Port numbers 0-1023 – Well known ports.

These are allocated to server services by the Internet Assigned Numbers Authority (IANA). e.g Web servers normally use port 80 and SMTP servers use port 25.

Ports 1024-49151- Registered Port

These can be registered for services with the IANA and should be treated as semi-reserved. User-written programs should not use these ports.

Ports 49152-65535-Free to use these in client programs

These are used by client programs and you are free to use these in client programs. When a Web browser connects to a web server the browser will allocate itself a port in this range. Also known as ephemeral ports.

Hope it helps :-)


Ports less than 1024 are usually reserved for system operations, after that you just need to avoid anything that you know will be in use on the machine(s) your program may run on. If you don't know that, then make the port a configurable setting.


You could use any port you like but suggest using one that is
1) not currently being used by another application (run resmon.exe on windows7 to see what ports are in use)
2) not a well known port of another service (eg 443, HTTPS)
3) not an OS 'reserved' port; that is a port less than 1024.

See this list for more

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜