网络示例代码应该使用哪个端口号? [英] Which port number should be used for network example code?

查看:28
本文介绍了网络示例代码应该使用哪个端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个 Haskell 网络示例,但我不知道应该使用哪个端口.

I've written a little Haskell network example, but i don't know, which port i should use.

我在找到的 IETF 论文或 维基百科的端口号列表中找不到示例端口号,但也许在编程社区中有一个通用的端口号.

i couldn't find a example port number in the IETF papers i found or in Wikipedia's list of port numbers, but maybe there is a common port number in the programming community.

推荐答案

端口的有效数字(与编程语言无关)是:0 到 2^16-1 = 0 到 65535
那是因为端口号是 16 位长.

Valid numbers for ports (regardless of the programming language) are: 0 to 2^16-1 = 0 to 65535
That is because a port number is 16 bit length.

不过端口分为:
知名端口:0 到 1023(用于系统服务,例如 HTTP、FTP、SSH、DHCP ...)
注册/用户端口:1024 到 49151(您可以将其用于您的服务器,但要小心一些著名的应用程序:例如 Microsoft SQL Server 数据库管理系统 (MSSQL) 服务器或 Apache Derby 网络服务器在这个范围内,即不建议将 MSSQL 的端口分配给您的服务器,否则如果 MSSQL 正在运行,那么您的服务器很可能由于端口冲突而无法运行)
动态/私有端口:49152 到 65535.(不用于服务器,而是用于客户端,例如在 NATing 服务中)

However ports are divided into:
Well-known ports: 0 to 1023 (used for system services e.g. HTTP, FTP, SSH, DHCP ...)
Registered/user ports: 1024 to 49151 (you can use it for your server, but be careful some famous applications: like Microsoft SQL Server database management system (MSSQL) server or Apache Derby Network Server are already taking from this range i.e. it is not recommended to assign the port of MSSQL to your server otherwise if MSSQL is running then your server most probably will not run because of port conflict )
Dynamic/private ports: 49152 to 65535. (not used for the servers rather the clients e.g. in NATing service)

在编程中,你的服务器可以使用0到65535之间的任意数字,但是你应该坚持上面提到的范围,否则由于端口冲突,一些系统服务或一些应用程序将无法运行.
在此处检查大多数端口的列表:https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

In programming you can use any numbers 0 to 65535 for your server, however you should stick to the ranges mentioned above, otherwise some system services or some applications will not run because of port conflict.
Check the list of most ports here: https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

这篇关于网络示例代码应该使用哪个端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆