有没有办法指定tcpClient中使用的本地端口?
我目前正在使用此函数调用来创建我的tcpClient:
clientSocket = new TcpClient("localhost", clientPort);
但clientPort
是服务器的端口。
有没有办法让我使用tcpClient指定客户端端口?
谢谢
采用IPEndPoint的构造函数重载允许您将TcpClient的内部Socket绑定到特定端口:
IPAddress ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0]; IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, clientPort); TcpClient clientSocket = new TcpClient(ipLocalEndPoint); clientSocket.Connect(remoteHost, remotePort);
- 如何使用SQL查询更新表中的多个行?
- 开源ASP.NET甘特图Web控件
- 检查Silverlight中的互联网连接
- ASP.net Core 2.0中的appsettings.json预览配置GetSection null
- ‘Compare’是’System.ComponentModel.DataAnnotations.CompareAttribute’和’System.Web.Mvc.CompareAttribute’之间的模糊引用。
- 当没有找到结果时,处理ExecuteScalar返回null
- 可变长度整数编码
- 动态创建控件并在回发中保存控件值 – ASP.Net C#
- 为什么DataBinding没有传播到UserControl