Boost C++ Libraries: Ticket #13463: Boost UDP multicast sender not using correct port https://svn.boost.org/trac10/ticket/13463 <p> I follow this code to create a UDP multicast receiver: <a href="http://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio/example/cpp11/multicast/sender.cpp">http://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio/example/cpp11/multicast/sender.cpp</a> </p> <p> I modify the code with these for predefined values: </p> <p> class receiver: </p> <blockquote> <p> short multicast_port = 13000; </p> </blockquote> <p> in main(): </p> <blockquote> <p> <em>if (argc != 2) and the code for argv that follows are commented out </em></p> </blockquote> <blockquote> <p> sender s(io_context, boost::asio::ip::make_address("192.168.0.255")); </p> </blockquote> <p> The first 3 octets match that of the local network. I check with Wireshark. It shows me that the packages are sent with source port of 53916, and destination port 0. Running the code again gives a source port of 59483, and destination port 0. </p> <p> What is causing the source port to be different from specified value? How can I force it to use the specified port number? Thanks. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13463 Trac 1.4.3 anonymous Sun, 04 Mar 2018 01:12:23 GMT attachment set https://svn.boost.org/trac10/ticket/13463 https://svn.boost.org/trac10/ticket/13463 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">UdpMulticastSender_1_66.cpp</span> </li> </ul> Ticket anonymous Sun, 04 Mar 2018 01:15:14 GMT <link>https://svn.boost.org/trac10/ticket/13463#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13463#comment:1</guid> <description> <p> I have previously tested the unicast UDP time server (<a href="http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/tutorial/tutdaytime6/src.html">http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/tutorial/tutdaytime6/src.html</a>) and client (<a href="http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/tutorial/tutdaytime4/src.html">http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/tutorial/tutdaytime4/src.html</a>) provided sample codes. They work, and the port specified is correctly observed with Wireshark. Could someone tell me what went wrong with this UDP multicast sender? </p> </description> <category>Ticket</category> </item> <item> <author>nguyen.tnhoang@…</author> <pubDate>Sun, 04 Mar 2018 01:32:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13463#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13463#comment:2</guid> <description> <p> OK, I manage to narrow down the error, but not sure how it happens. In the sender() class constructor: </p> <blockquote> <p> sender(boost::asio::io_context&amp; io_context, const boost::asio::ip::address&amp; multicast_address) </p> <blockquote> <p> : endpoint_(multicast_address, multicast_port), socket_(io_context, endpoint_.protocol()), timer_(io_context), message_count_(0) </p> </blockquote> </blockquote> <p> I change the line: </p> <blockquote> <p> socket_(io_context, endpoint_.protocol()), </p> </blockquote> <p> into </p> <blockquote> <p> socket_(io_context, udp::endpoint(udp::v4(), 13000)), </p> </blockquote> <p> It works properly. Wireshark shows the packages sent with that specified source port of 13000. However, if I change it to: </p> <blockquote> <p> socket_(io_context, udp::endpoint(udp::v4(), multicast_port)), </p> </blockquote> <p> It still won't work, despite multicast_port being specified as 13000. Please help. I need the source port to be dynamically set. Thank you. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 04 Mar 2018 02:41:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13463#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13463#comment:3</guid> <description> <p> I change the order of the private members in the code: </p> <p> private: </p> <blockquote> <p> unsigned short multicast_port = 13000; <em>30001 int max_message_count = 10; boost::asio::ip::udp::endpoint endpoint_; boost::asio::ip::udp::socket socket_; boost::asio::steady_timer timer_; int message_count_; std::string message_; </em></p> </blockquote> <p> now everything works as intended. Please close the ticket. </p> </description> <category>Ticket</category> </item> </channel> </rss>