我遵循了有关套接字编程的简短教程,最终能够在同一台计算机上向自己发送数据。现在我希望能够将数据发送到我家中的另一台计算机。
这就是我设置端点的方式。
服务器:
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAdress = host.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAdress, 11000);
客户:
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAdress = host.AddressList[0];
IPEndPoint remoteEndPoint = new IPEndPoint(ipAdress, 11000);
我以为我所要做的就是将客户端上的 IP 设置为接收计算机的 IP,如下所示:
IPAddress ipAdress = IPAddress.Parse("192.168.200.97");
IPEndPoint remoteEndPoint = new IPEndPoint(ipAdress, 11000);
但这似乎不起作用。当我尝试它时,它说服务器正在主动拒绝连接。
我想出了什么问题。第一次进入
IPAddress ipAdress = host.AddressList[0];
没有给我我自己的服务器 IP 地址。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句