【问题标题】:How to I get the UDP remote endpoint when using boost asio?使用 boost asio 时如何获取 UDP 远程端点?
【发布时间】:2013-05-08 01:40:32
【问题描述】:

假设我在 UDP 套接字(加入了多播组)上重新编写了异步接收处理程序:

         udpSocket.async_receive(boost::asio::buffer(buffer, sizeof(buffer)),
                                 boost::bind(&receiveCallback,
                                              boost::asio::placeholders::error,
                                              boost::asio::placeholders::bytes_transferred));

这里的想法是我想在接收UDP数据包时在receiveCallBack中获取remote地址和端口。怎么做?有特定的占位符吗?如果没有,在回调中如何获取该信息?

【问题讨论】:

    标签: c++ boost boost-asio


    【解决方案1】:

    我认为您可能想要使用receive_from 调用,它接受boost::asio::ip::udp::endpoint 来捕获发件人数据。

    在 boost asio 示例here 中有一个示例多播接收器。特别是这个块:

    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));
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多