[Boost-bugs] [Boost C++ Libraries] #13461: C++ Boost UDP multicast errors out with socket.set_option()

Subject: [Boost-bugs] [Boost C++ Libraries] #13461: C++ Boost UDP multicast errors out with socket.set_option()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-03-03 04:30:29

#13461: C++ Boost UDP multicast errors out with socket.set_option()
 Reporter: nguyen.tnhoang@… | Owner: (none)
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: None
  Version: Boost 1.66.0 | Severity: Showstopper
 Keywords: udp multicast set_option |
 I am following an example of Boost UDP multicast sending and receiving
 receiver-with-boost-asio/12749727#12749727). I make some modifications to
 predefine IP and port:

 #include <ctime>
 #include <iostream>
 #include <string>
 #include <boost/array.hpp>
 #include <boost/bind.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/asio.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/thread.hpp>
 using boost::asio::ip::udp;
 using std::cout;
 using std::cin;
 using std::endl;

 void read(boost::asio::ip::udp::socket& socket)
         boost::asio::ip::udp::endpoint sender;
         std::vector<char> buffer;
         std::size_t bytes_readable = 0;
         for (int i = 0; i < 3; ++i)
                 // Poll until data is available.
                 while (!bytes_readable)
                         // Issue command to socket to get number of bytes

                         // Get the value from the command.
                         bytes_readable = num_of_bytes_readable.get();

                         // If there is no data available, then sleep.
                         if (!bytes_readable)

                 // Resize the buffer to store all available data.

                 // Read available data.
                         boost::asio::buffer(buffer, bytes_readable),

                 // Extract data from the buffer.
                 std::string message(buffer.begin(), buffer.end());

                 // Output data.
                 std::cout << "Received message: ";
                 std::cout << message << std::endl;

 void write(boost::asio::ip::udp::socket& socket,
 boost::asio::ip::udp::endpoint& destination)
         std::string message;
         for (unsigned int i = 0; i < 3; ++i)
                 std::ostringstream stream;
                 stream << i;
                 message = stream.str();
                 socket.send_to(boost::asio::buffer(message), destination);
                 std::cout << "Sent message: " << message << std::endl;

 int main()
         bool receiver = false;
         boost::asio::ip::address address =
         unsigned short port = boost::lexical_cast<unsigned short>("13");

         // Create socket.
         using boost::asio::ip::udp;
         boost::asio::io_service service;
         udp::socket socket(service);

         // Allow other processes to reuse the address, permitting other
 processes on
         // the same machine to use the multicast address.

         // Guarantee the loopback is enabled so that multiple processes on
 the same
         // machine can receive data that originates from the same socket.
         udp::endpoint destination(address, port);

         // Join group.
         namespace ip = boost::asio::ip;
         // Start read or write loops based on command line options.
         if (receiver) read(socket);
         else write(socket, destination);

         return 0;

 An error is thrown here:

 with this detail:

 Microsoft C++ exception: boost::exception_detail::clone_impl > at memory
 location 0x0040F470. occurred

 Can someone please tell me what went wrong? Thanks.

Ticket URL: <https://svn.boost.org/trac10/ticket/13461>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2018-03-03 04:34:48 UTC