UDP async_receive的boost :: asio错误 [英] boost::asio error for UDP async_receive

查看:237
本文介绍了UDP async_receive的boost :: asio错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了来自boost :: asio的奇怪错误的问题.我正在实现一半的TFTP服务器(仅服务器->客户端).我在第一个套接字的端口69上获得了第一个RRQ数据包,然后创建另一个套接字来进行DATA,ACK交换.我在该套接字上启动async_receive(),然后对第一个数据包执行send().然后,我得到接收程序的处理程序回调(我假设有ACK进来),它给出错误无法建立连接,因为目标计算机主动拒绝了它",我从另一个线程了解到这意味着ERROR_PORT_UNREACHABLE.

I'm having a problem with a weird error from boost::asio. I am implementing half of a TFTP server (server->client only). I get the first RRQ packet on port 69 on the first socket and then create another socket to carry out the DATA,ACK exchange. I start an async_receive() on that socket and then do a send() of the first packet of data. I then get the handler callback for the receive (I assume the ACK coming in) and it gives the error "No connection could be made because the target machine actively refused it" which I understand from another thread here means ERROR_PORT_UNREACHABLE.

我真的不明白接收呼叫如何导致UNREACHABLE错误,因为我没有收到任何东西.我检查了send()的结果,那里没有错误.

I really don't understand how a receive call can cause an UNREACHABLE error since I am not reaching out to anything, I am receiving. I checked the result of the send() and there is no error there.

我检查了套接字中的本地端点和远程端点(错误前后),它们的IP地址和端口都正确.

I checked the local and remote endpoints in the socket (before and after the error) and they have the correct IP address and port for both.

有什么想法吗?我到处搜寻,找不到其他人遇到这个问题.多数结果导致我出现stackoverflow,所以我在这里问.

Any ideas? I've googled around and can't find anyone else having this problem. Most results led me to stackoverflow so I ask here.

编辑- 我的问题是我正在使用调试器.当我开始发送第一个数据包时,客户端在大约一秒钟内发送了十几个请求之后,客户端超时并放弃了,我的数据来不及了.当我没有断点运行时,它可以正常工作.感谢大家的建议.正是看着Wireshark中的数据包为我提供了线索.

推荐答案

发送成功的原因是因为发送仅表明已将数据包提供给OS.特别是,操作系统随后将该数据包发送到目的地,并以IP数据包作为响应,该IP数据包指示主机未在侦听.然后,您的操作系统会收到它,并在套接字上设置一个标志,导致下一次读取失败.由于您已经在执行异步接收,因此导致接收返回错误.

The reason the send succeeds is because the send simply indicates that the packet has been given to the OS. In particular, the OS then sends that packet to the destination, and it responds with an IP packet indicating that the host is not listening. Your OS then receives it, and sets a flag on your socket that causes the next read to fail. Since you're already performing an asynchronous receive, it cause the receive to return the error.

如果可能的话,我强烈建议您使用Wireshark或类似工具观察UDP交换,并查看是否可以识别任何其他问题.我对TFTP协议不熟悉,因此无法在其中提供很多输入.

If possible, I would highly recommend using wireshark or something similar to watch the UDP exchange, and see if you can identify any other issue. I'm not familiar with the TFTP protocol, and can't provide much input there.

这篇关于UDP async_receive的boost :: asio错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆