您如何决定使用哪个端口?
这有点主观,因为可以说没有规则。每次创建服务器时,我都会想,“最好使用的端口是什么?”我猜答案是“任何,只要用户可以更改它”。那么,其他人如何决定如何选择默认端口呢?就个人而言,如果与 HTTP 相关,我喜欢使用 8000 之类的东西,并且我注意到这是一个非常常见的趋势。但如果 8000 已经在使用怎么办?用8001吗?这似乎有点特别,我想确实如此。
显然我不是第一个问这个问题的人。 IANA 维护着一个端口号列表...这让我看到了未分配的范围 (48620 -49150)。我想我们确实应该使用这些,但为什么没有更多的程序员这样做呢?您如何决定使用哪个;如果每个人都从#1 开始,那么我们都会使用 48620。
This is a little subjective, as there are no rules so to speak. Every time I create a server, I think to myself, "What is the best port to use?" I guess an answer is "Any, as long as the user can change it." So, how does everyone else decide how to choose the default port? Personally, I like to use something like 8000-something if it's HTTP related, and I've noticed this is a pretty common trend. But what if 8000 is already in use? Use 8001? It seems a little ad-hoc, and I suppose it is.
Clearly I'm not the first to have asked this question; IANA maintain a port numbers list... Which leads me on to the unassigned range (48620-49150). I guess we should really be using these, but why don't more programmers do so? How do you decide which to use; if everyone started at #1, then we'd all be using 48620.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我认为您已经尽可能地回答了您的问题;除了您所说的之外,实际上并没有您可以遵循的严格规则。但一般来说:
(如果您想知道如何选择令人难忘的端口号,我曾经与一个人一起工作,他根据同事的电话分机记住了端口号。)
I think you've pretty much answered your question as much as is possible; there isn't really a strict rule you can follow here beyond what you've said. But generally:
(And if you want a tip for picking memorable port numbers, I once worked with someone who remembered port numbers based around the telephone extensions of his co-workers.)
一些易于记忆且适当的未分配端口(根据 IANA):
27182 (e)
31415 (pi)
60221 (avagadro's)
Some easy to remember and appropriately nerdy unassigned (per IANA) ports:
27182 (e)
31415 (pi)
60221 (avagadro's)
在测试期间...始终端口 #666 ;)
During testing... always port #666 ;)
怎么样:
How about:
你回答了你自己的问题吗?选择任何未分配的端口并允许用户更改它。
You answered your own question? Pick any unassigned port and allow the user to change it.
我更喜欢这种方式:(python代码如下)
然后我选择我最喜欢的数字。
或者,如果您对可接受的数字有更严格的限制,则可以更改范围。
I prefer this way: (python code following)
And then I pick the number which I like the most.
Or course, change the range if you have some stricter limits of what are acceptable numbers.
经过快速谷歌搜索以确保其清晰后,我通常只选择一些对个人有意义的数字。
After a quick Google search to make sure it's clear, I generally just choose a number of personal significance.
我建议永远不要使用像 5 位数字这样的大端口,因为它可能会影响其他操作系统进程并分配临时端口。由于其限制,您将开始收到“已在使用错误”。
I'd suggest never use a port that is a big number like 5 digits, as it might hit some other operation system processes and assigns the Ephemeral ports. You would start to get 'Already in use errors' due to its limitations.