如何在使用boost asio时获得UDP远程端点
How to I get the UDP remote endpoint when using boost asio?
假设我已经重新编码了UDP套接字(加入多播组)上的异步接收处理程序:
udpSocket.async_receive(boost::asio::buffer(buffer, sizeof(buffer)),
boost::bind(&receiveCallback,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
这里的想法是,我想在接收UDP数据包时获得远程地址和端口在receiveCallBack。怎么做呢?是否有特定的占位符?如果不是,在回调中如何获得该信息?
我想你可能想使用receive_from
调用,它接受boost::asio::ip::udp::endpoint
来捕获发送方数据。
在这里的boost asio示例中有一个示例多播接收器。特别是这个块:
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));
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 在C++中使用cURL和多线程
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 从udp接收帧对于人脸识别来说太慢
- 在cuda线程之间共享大量常量数据
- 如何将元素添加到数组的线程安全函数?
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- C++ 提升 UDP 接收器在放入线程时失败
- 来自 boost 的 udp 服务器不适用于多线程,但仅在主线程上工作
- UDP以不同的线程发送和接收
- Boost Asio udp 解析器返回错误的端点迭代器
- 如何从udp端点获取*my*ip
- boost::asio async_receive_from线程之间共享的 UDP 端点
- 在多线程UDP服务器中使用多个套接字
- 如何在使用boost asio时获得UDP远程端点
- UDP接收线程占用太多CPU资源
- 实现多线程UDP服务器(线程池?)的问题