Boost logo

Boost Users :

Subject: [Boost-users] udp::socket::socket() vs udp::socket::open()
From: Chris Stankevitz (chrisstankevitz_at_[hidden])
Date: 2013-02-11 11:31:32


Hello,

The UDP async server example opens the udp socket like so:

a) udp::socket::socket(io_service, udp::endpoint(udp::v4(), 13))

Boost's comment regarding this invocation:
   * This constructor creates a datagram socket and automatically opens it bound
   * to the specified endpoint on the local machine. The protocol used is the
   * protocol associated with the given endpoint.

Please consider the udp::socket constructor that takes only an io_service:
b) explicit basic_datagram_socket(boost::asio::io_service& io_service)

Commented as:
   * This constructor creates a datagram socket without opening it. The open()
   * function must be called before data can be sent or received on the socket.

And finally, udp::socket::open:
(c) void open(const protocol_type & protocol = protocol_type());

Please note that (a) takes an endpoint while (c) takes a protocol.

===

Question:

How can I effectively call (a) using the two-part invocation (b) then (c)?

Answer:

1) Just call udp::socket::open(endpoint(udp::v4(), 13));

2) This is impossible because (a) takes a endpoint while (c) wants a protocol

3) Why would you want to do that you moron?

4) Why don't you write your own udp::socket::open that takes an
endpoint if you are so smart? Try giving back to the community
instead of just taking. You are a leech and not worthy of reading this
mailing list let alone posting to it.

5) none of the above

Note: (1) fails with error: no matching function for call to
'boost::asio::basic_datagram_socket<boost::asio::ip::udp>::open(boost::asio::ip::udp::endpoint)'

Thank you,

Chris


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