Вопрос

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?

Это было полезно?

Решение

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.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top