本文整理汇总了C++中boost::asio::ip::udp::socket::set_option方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::set_option方法的具体用法?C++ socket::set_option怎么用?C++ socket::set_option使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::ip::udp::socket
的用法示例。
在下文中一共展示了socket::set_option方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receiver
receiver(boost::asio::io_service& io_service,
const boost::asio::ip::address& listen_address,
const boost::asio::ip::address& multicast_address)
: socket_(io_service)
{
// Create the socket so that multiple may be bound to the same address.
boost::asio::ip::udp::endpoint listen_endpoint(
listen_address, multicast_port);
socket_.open(listen_endpoint.protocol());
socket_.set_option(boost::asio::ip::udp::socket::reuse_address(true));
socket_.bind(listen_endpoint);
// Join the multicast group.
socket_.set_option(
boost::asio::ip::multicast::join_group(multicast_address));
socket_.async_receive_from(
boost::asio::buffer(data_, max_length), sender_endpoint_,
boost::bind(&receiver::handle_receive_from, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
示例2: thread
SC_UdpInPort(struct World * world, int inPortNum):
mWorld(world), mPortNum(inPortNum), udpSocket(ioService)
{
using namespace boost::asio;
BOOST_AUTO(protocol, ip::udp::v4());
udpSocket.open(protocol);
udpSocket.bind(ip::udp::endpoint(protocol, inPortNum));
boost::asio::socket_base::send_buffer_size option(65536);
udpSocket.set_option(option);
#ifdef USE_RENDEZVOUS
if (world->mRendezvous) {
thread thread( boost::bind( PublishPortToRendezvous, kSCRendezvous_UDP, sc_htons(mPortNum) ) );
mRendezvousThread = std::move(thread);
}
#endif
startReceiveUDP();
}