2017-04-13 10:11 GMT+08:00 TONGARI J <tongari95@gmail.com>:
2017-04-13 9:01 GMT+08:00 jupiter via Boost-users <boost-users@lists.boost.org>:
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'.

(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.

Actually the example doesn't seem correct, it uses async_receive w/o connecting to a remote endpoint first, while the doc says:

"The async_receive operation can only be used with a connected socket. Use the async_receive_from function to receive data on an unconnected datagram socket."

Anyway, the listen_endpoint in the example is a local endpoint which is bind to the client, this may seem weird as it's actually a server in traditional sense.

BTW, here's the same example rewritten with co2+act:

...if you're interested in what the code written in stackless coroutine would like.