简体   繁体   中英

Why can boost asio udp connection throw “send: Connection refused”?

I assumed that udp connection does not really care if there is any peer at all on the other side so why could boost asio udp connection throw "send: Connection refused" on socket->send( boost::asio::buffer( data.get(), length ) ); call (I am sending from Linux to Windows, only sending not trying to read any thing)? Is it some network card error or what could it be?

Use send_to . After all, UDP is a connectionless protocol.

Boost.Asio is throwing an error with a value of boost::asio::error::connection_refused because the underlying socket's send*() operation is returning an error code of ECONNREFUSED . Per the udp manual page, send*() functions are permitted to return 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.

While it can be odd to receive a connection related error on a connectionless protocol, the service is still permitted to return detected errors. The unreliable part of the protocol prevents the caller from receiving acknowledgement that the a message was received by the destination. However, this does not preclude the service from reporting a connection refused error if it knows the destination did not receive the message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM