Is broadcasting possible via Boost Asio TCP

672 views Asked by At

http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/ip__tcp/socket.html

Boost::asio::ip::tcp::socket does have an option where one can set the permission of allowing the broadcast message. So my question is, is broadcasting possible via Boost Asio TCP Socket?? If yes, any help in this matter would be highly appreciated.

Thanks in advance.

1

There are 1 answers

0
dau_sama On BEST ANSWER

the TCP protocol does not support broadcasting, for that you should use UDP.

If you check the boost source code: http://www.boost.org/doc/libs/1_57_0/boost/asio/socket_base.hpp

they have some documentation concerned this:

  /// Socket option to permit sending of broadcast messages.
  /**
   * Implements the SOL_SOCKET/SO_BROADCAST socket option.
   *
   * @par Examples
   * Setting the option:
   * @code
   * boost::asio::ip::udp::socket socket(io_service); 
   * ...
   * boost::asio::socket_base::broadcast option(true);
   * socket.set_option(option);
   * @endcode
   *
   * @par
   * Getting the current option value:
   * @code
   * boost::asio::ip::udp::socket socket(io_service); 
   * ...
   * boost::asio::socket_base::broadcast option;
   * socket.get_option(option);
   * bool is_set = option.value();
   * @endcode
   *
   * @par Concepts:
   * Socket_Option, Boolean_Socket_Option.
   */

In short, instead of using a tcp socket, switch to udp, just read about it before, as delivery of packets won;'t be guaranteed.