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?

- 772
- 10
- 62
- 134
2 Answers
-
I meant on established connection after some time. Exception comes and goes during application execution on one connection. Meaning we have sent at rate 1 message a second. and we can send 100 messages, then get 10 exceptions then send 1000 more messages on same connection sucsessfully. – DuckQueen Feb 12 '14 at 09:27
-
@DuckQueen: Giving it a little bit more thought, forget about `.connect` and `.send` and just use `send_to`. Whether it's possible to actually connect to a UDP socket depends on the OS, see http://stackoverflow.com/questions/9741392/can-you-bind-and-connect-both-ends-of-a-udp-connection. – Zeta Feb 12 '14 at 09:36
-
As non-intuitive as it is, [UDP](http://linux.die.net/man/7/udp) is permitted to return an `ECONNREFUSED` error even though it is a connection-less protocol. – Tanner Sansbury Feb 12 '14 at 18:24
-
@TannerSansbury it works by the mechanism of ICMP Destination Unreachable (Port Unreachable) messages. – Ruslan Dec 30 '20 at 22:17
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.

- 51,153
- 9
- 112
- 169