TCP 调试错误 C#
public Server([Optional, DefaultParameterValue(0x6c1)] int port, [Optional, DefaultParameterValue("127.0.0.1")] string ip)
{
this.IP = IPAddress.Parse(ip);
this.Port = port;
this.listenerConnection = new TcpListener(this.IP, this.Port);
this.listenerConnection.Start();
this.listenerThread = new Thread(new ThreadStart(this.listen));
this.listenerThread.Start();
}
是我的代码,它运行良好,但是当我调试它时,我收到消息:
指定的参数超出了有效值的范围。参数名称:端口
有人可以帮忙吗?
public Server([Optional, DefaultParameterValue(0x6c1)] int port, [Optional, DefaultParameterValue("127.0.0.1")] string ip)
{
this.IP = IPAddress.Parse(ip);
this.Port = port;
this.listenerConnection = new TcpListener(this.IP, this.Port);
this.listenerConnection.Start();
this.listenerThread = new Thread(new ThreadStart(this.listen));
this.listenerThread.Start();
}
is the code I have, it runs fine but when I debug it, I get the message:
Specified argument was out of the range of valid values. Parameter name: port
Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,那么
port
超出了有效值的范围,该范围在 IPEndPoint.MinPort 和 IPEndPoint.MaxPort。Well, then
port
is out of the range of valid values, which is between IPEndPoint.MinPort and IPEndPoint.MaxPort.您是否尝试过使用您机器的 IP 地址?您可以使用以下代码来获取正在运行应用程序的计算机的 IP 地址:
此外,您可能需要考虑使用默认端口 > 5000。因为 0 到 5000 之间有许多端口已被服务保留或已使用。
Have you tried using the IPAddress of your machine? You can use the following code to obtain the IPAddress of the machine you are running the application on:
Additionally, you may want to consider using a default port > 5000. As there are many ports between 0 and 5000 that are reserved or already use by services.