- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我第一次使用 IPEndPoint,请原谅我缺乏经验。
如果我像这样创建一个 IPEndPoint:
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.25"), 0);
是否有可能端口 0 已经在使用中,从而产生异常?这里是否有任何类型的约定用于使用哪个本地端口号?我应该只使用随机生成的小于 65,536 的数字吗?是否有最佳或最安全的方法来选择端口,这是否重要?
此特定实例中的用例仅供我了解更多信息。我现在正在摆弄发送 UDP 广播 WOL 数据包,但稍后我希望进入更复杂的代码。我只是想确保我了解最佳实践。
最佳答案
根据 IANA
Port numbers are assigned in various ways, based on three ranges: System Ports (0-1023), User Ports (1024-49151), and the Dynamic and/or Private Ports (49152-65535); the difference uses of these ranges is described in [RFC6335]. System Ports are assigned by IETF process for standards-track protocols, as per [RFC6335]. User Ports are assigned by IANA using the "IETF Review" process, the "IESG Approval" process, or the "Expert Review" process, as per [RFC6335]. Dynamic Ports are not assigned.
同样来自 UdpClient(port) ctor MSDN 文档:
If you pass 0 to the constructor, the underlying service provider will assign a port number.
关于c# - 本地 IPEndPoint 创建的端口选择。端口号重要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20434627/
我正在使用需要“IPEndPoint”的第三方 dll。由于用户可以输入 IP 地址或主机名,因此我需要先将主机名转换为 IP 地址,然后才能创建 IPEndPoint。在 .net 中是否有任何功能
我有一个 IPEndPoint a 和 b,其 IPAddress 和 Port 完全相同,但 IPEndPoint 上的 == 运算符未返回 true。更奇怪的是,我试图通过简单地单独比较 IP 地
因为 IPEndpoint 包含一个 ToString() 方法输出: 10.10.10.10:1010 还应该有 Parse() 和/或 TryParse() 方法,但没有。 我可以在 : 上拆分字
这是我第一次使用 IPEndPoint,请原谅我缺乏经验。 如果我像这样创建一个 IPEndPoint: IPEndPoint localEndPoint = new IPEndPoint(IPAdd
根据 the documenation on MSDN , IPEndPoint 可以设置其 Address 和 Port 属性。 为什么这个类被设计成可变的?对于相同的 reasons 似乎它应该是
当我进行绑定(bind)时,我可以在我的套接字上分配的端口的最大值是多少? 例子: int port = 0; //How far can i go? Socket m_mainSocket; m_m
我快把自己逼疯了。 Microsoft 提供了一种使用构造函数为新 TCPClient 绑定(bind)本地网络适配器和端口的绝妙方法: TcpClient newClient = new TcpCl
为什么不选择使用 UInt32(用于 IP)和 UInt16(用于端口)? 最佳答案 无符号整数不是 CLS compliant .因此,许多语言不支持它们,并且在 .NET 基类库 (BCL) 中尽
对于我的 .NET C# 应用程序,我们有一些模块需要通过 TCP/IP 协议(protocol)进行通信。 我决定使用 Microsoft 的 System.Net.Sockets API “Tcp
我正在尝试使用 dnx 在 Linux 上运行 .NET 程序。 操作系统:centos 7 我安装了 mono 和 coreclr,并且 dnvm 能够在两者之间切换。版本为1.0.0-beta7-
我是一名优秀的程序员,十分优秀!