简体   繁体   English

C#配置TCPClient客户端的端口

[英]C# configuring TCPClient client's port

I have coded TCPClient() in C# to communicate with another device on LAN. 我已经用C#编写了TCPClient()以便与LAN上的另一台设备通信。 I only have to specify the target IP and port number. 我只需要指定目标IP和端口号。

Now I am coding something quite similar to it. 现在,我正在编写与之非常相似的东西。 However, it specifies that the client port from my PC has to be something greater than 1024 . 但是,它指定我PC的客户端端口必须大于1024 How can I configure that? 我该如何配置? does this mean that VS automatically takes care of that if not specified? 这是否意味着VS(如果未指定)会自动进行处理?

TcpClient(IPEndPoint) can be used to specify the client port (just use IPAddress.Any for the address part). TcpClient(IPEndPoint)可用于指定客户端端口(仅将IPAddress.Any用于地址部分)。 As documented on Socket.Bind and wikipedia:ephemeral_port , by default a port higher than 1024 would be used. Socket.BindWikipedia:ephemeral_port所记录 ,默认情况下将使用高于1024的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM