我试图为一个类项目编写一个TFTP客户端。使用UdpClient类,我可以成功地从服务器请求数据,但是返回的数据包永远不会到达我的代码。
我的防火墙已关闭。我可以在wirehark中观察返回的数据包,但是UdpClient.Receive无限期阻塞。
mUdpClient在构造函数中初始化如下: mUdpClient = new UdpClient();
mUdpClient这样连接
public void connect(String host, int port) {
mServerAddress = System.Net.Dns.GetHostAddresses(host)[0];
var endPoint = new IPEndPoint(mServerAddress, port);
mUdpClient.Connect(endPoint);
}
连接后,我发送成功的请求(在wireshark中观察到)
这就是我的接收代码的样子
private void receiveResponse() {
var newEndpoint = new IPEndPoint(IPAddress.Any, 0);
byte[] response = mUdpClient.Receive(ref newEndpoint);
Console.Out.WriteLine(response);
}
这已在我的Surface Pro和在Debian下运行的Windows 8.1 VirtualBox VM上进行了测试。
请注意,由于您在UDP套接字上使用Connect()方法,因此您只会看到实际上是从该IPEndPoint发送的数据报。如果您的远程主机出于某种原因使用其他IPEndPoint将数据发送回给您,您将看不到它。因此,也许尝试不使用默认的主机功能(即,不要调用Connect ...只需在每个Send()调用中提供远程IPEndPoint)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句