[英]boost::asio UDP server, how to send without having to do a receive_from first?
In all the examples of the udp server, there is the code below.在udp服务器的所有例子中,都有下面的代码。 But in my case, I just want server to send, whether or not there is a client ready to receive.
但就我而言,我只希望服务器发送,无论是否有客户端准备好接收。 So would like to not have to use the receive_from call to get the endpoint.
所以想不必使用receive_from 调用来获取端点。 Can I do this in boost?
我可以在 boost 中这样做吗?
size_t length = sock.receive_from(
boost::asio::buffer(data, max_length), sender_endpoint);
sock.send_to(boost::asio::buffer(data, length), sender_endpoint);
The documentation of send_to actually contains an example on how to construct the endpoint address and send to it, without receiving from the endpoint first. send_to的文档实际上包含一个关于如何构造端点地址并将其发送给它的示例,而无需先从端点接收。 To cite:
引用:
boost::asio::ip::udp::endpoint destination(
boost::asio::ip::address::from_string("1.2.3.4"), 12345);
socket.send_to(boost::asio::buffer(data, size), destination);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.