Boost logo

Boost :

From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2008-05-13 04:33:52

Me here wrote:
> Hi,
> I'm writing program with asio from 1.35.0 to read the
> data from a hardware device which sends data to my PC
> to port 7000. The sample below fails on Windows with
> exception code 10022, text "An invalid argument was
> supplied".
> Where's the fault? Can someone help please?

A belated response, sorry. You need to bind the UDP socket to an
endpoint before you can receive packets on it.

> udp::endpoint sender_endpoint( udp::v4(), 7000 );
> udp::socket socket(io_service);
> udp::v4() );

Try adding:

   udp::endpoint local_endpoint(udp::v4(), 7000);

here. There's also a convenience constructor for udp::socket that does
the open() and bind for you, so you could instead write:

   udp::endpoint local_endpoint(udp::v4(), 7000);
   udp::socket socket(io_service, local_endpoint);

Furthermore ...

> size_t len = socket.receive_from(
> boost::asio::buffer(packet), sender_endpoint);

any existing value in the sender_endpoint is ignored here, so you may as
well leave the sender_endpoint as a default-constructed udp::endpoint


Boost list run by bdawes at, gregod at, cpdaniel at, john at