c++ - 为什么可以 boost asio udp 连接抛出 "send: Connection refused"?

标签 c++ exception boost udp boost-asio

我假设 udp 连接并不真正关心另一边是否有任何对等端,所以为什么可以 boost asio udp 连接在 socket->send( boost::asio::buffer( data.get(), length ) ); 调用(我从 Linux 发送到 Windows,只发送不尝试读取任何东西)?是网卡错误还是什么?

最佳答案

Boost.Asio 抛出值为 boost::asio::error::connection_refused 的错误,因为底层套接字的 send*() 操作正在返回一个ECONNREFUSED 的错误代码。根据 udp手册页,send*() 函数允许返回 ECONNREFUSED:

All errors documented for socket or ip may be returned by a send or receive on a UDP socket.

ECONNREFUSED
    No receiver was associated with the destination address. This might be caused by a previous packet sent over the socket.

虽然在无连接协议(protocol)上收到与连接相关的错误可能很奇怪,但仍允许该服务返回检测到的错误。协议(protocol)的不可靠部分阻止调用者接收到消息已被目的地接收的确认。但是,这并不排除服务在知道目标未收到消息的情况下报告连接被拒绝错误。

关于c++ - 为什么可以 boost asio udp 连接抛出 "send: Connection refused"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722900/

相关文章:

c++ - 为什么我们需要在重载 >> 和 << 运算符时返回对 istream/ostream 的引用?

c++ - CMake "uuid"链接失败

c++ - 任何人都可以演示 fl_filename_list 吗?

java - 为什么在 JNI 中调用纤程会在 JVM 中引发 StackOverflow?

c++ - Boost将单调时钟用作日志时间戳

python - boost python 错误消息 :terminate called after throwing an instance of 'boost::python::error_already_set'

java - 在 Java 绑定(bind)中循环遍历 OpenCV Mat

java - 我捕获了异常,但仍然看到它在日志中抛出

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

c# - 异常与返回码 : do we lose something (while gaining something else)?