Boost logo

Boost Users :

Subject: Re: [Boost-users] What is the effective way to use boost::asio::deadline_timer for udp socket receive_from?
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-04-13 02:42:58


On 13/04/2017 13:01, jupiter via Boost-users wrote:
> You are right, I did notice an example code given by
> http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/example/timeouts/blocking_udp_client.cpp
> where the async_receive and timer are used. I left this out in my
> original post because I have lots of issues from that example, let me
> know if you'd like me to have a separate post, here are the problems:
>
> (1) That example can only work with an IP address in local machine, if I
> change to a remote machine IP address, it got an error of "Exception:
> bind: Cannot assign requested address'.

Of course. You are specifying the address to listen at, which must be a
local address. The only reason it allows an IP at all is for machines
that have multiple adapters; you need to specify which adapter to listen
on, or use ip::address_v4::any() to listen on all adapters.

> (2) If my server is running at the same local machine with the same port
> number, it got an error of "Exception: bind: Address already in use".
>
> How can test that example? I need to add an async_send and I need to run
> it with a local server.

The server accepts two separate port numbers. The first is the port for
the TCP server itself, the second is the port for the UDP client. These
must be different, and the latter must be the same as the port used when
running the UDP client.

You need to run the server, one or both of the two TCP clients, and the
UDP client; the TCP client sends something to the server, which relays
it to the UDP clients.

Or at least that's what it looks like after spending 30 seconds reading
the code and associated comments.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net