为您的应用选择端口的指南
我有一个应用程序,它在端口上侦听来自各个客户端服务器上的脚本的信息。我需要决定应该分配给应用程序绑定哪个端口。我可以查看此列表并了解哪些端口不分配,但我对开发人员如何决定将端口分配给他们的应用程序感到困惑。它们只是随机的,还是有针对不同类型的应用程序使用特定端口范围的指南?
I have an application that listens on a port for information from scripts on various client servers. And I need to decide what port I should assign to the application to bind to. I can look at this list and know which ports not to assign, but I'm confused about how developers decide to assign ports to their application. Are they simply random, or are there guidelines to use specific port ranges for different types of applications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上是随机的。从 IANA 列表中的未分配/私有范围之一中选择一个端口,并期待最好的结果。
您可能想询问服务器和网络管理员是否有他们希望您使用的端口,因为他们可能需要配置防火墙/路由器/等。 (他们甚至可能知道正在使用哪些端口,并且能够为您提供有关可用端口的明确答案,但这将是非典型的。)
如果您的应用程序无法打开端口进行侦听,那么您将需要肯定有人会看到错误消息。这可能意味着其他东西正在使用该端口,因此您需要解决冲突。同样,如果客户端连接到该端口上的某些内容并收到“奇怪”的输出,请确保以合适的方式报告错误。
并且不要将此端口号硬编码到任何应用程序中。通过命令行选项、配置文件、环境变量等使其可配置。如果你让它很难改变,那么你肯定需要改变它。
It's basically random. Choose a port from one of the unassigned/private ranges in the IANA list and hope for the best.
You might want to ask the server and network administrators if there is a port they want you to use, as they might need to configure firewalls/routers/etc. (They might even know what ports are in use and be able to give you a definitive answer about a usable port, but this would be atypical.)
If your application can't open the port for listening, then you'll want to make sure somebody will see the error message. It probably means something else is using the port, so you'll need to resolve the conflict. Similarly, if the clients connect to something at that port and get "weird" output back, make sure that error gets reported in a suitable fashion.
And don't hard-code this port number into any of your applications. Make it configurable via command-line option, config file, environment variable, etc. If you make it hard to change, then you will certainly need to change it.
您的主要目标是获得一个不常用的东西,除此之外选择您喜欢的东西。
有时我会发挥创意,找到一种方法来计算对应用程序的有意义但模糊的引用。通常我会将应用程序名称中的字符转换为 ascii 值,将它们相加,然后根据可能的值乘以另一个数字,使其进入 1024-65000 范围。
Your main goal is to get one that isn't commonly used, beyond that pick something that you like.
I sometimes get creative and find a way to calculate a meaningful yet obscure reference to the app. Often I will convert the characters in the name of the app to ascii values, add them up and depending on the value possible multiply by another number to get it into the 1024-65000 range.