本文整理汇总了C++中boost::asio::ip::udp::socket::send_to方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::send_to方法的具体用法?C++ socket::send_to怎么用?C++ socket::send_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::ip::udp::socket
的用法示例。
在下文中一共展示了socket::send_to方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleReceive
void DiscoveryServer::HandleReceive(const boost::system::error_code& error) {
if (!error &&
std::string(m_recv_buffer.begin(), m_recv_buffer.end()) == DISCOVERY_QUESTION) {
m_socket.send_to(
boost::asio::buffer(DISCOVERY_ANSWER + boost::asio::ip::host_name()),
m_remote_endpoint);
}
Listen();
}
示例2: send
void Client::send(Peer peer) {
boost::asio::streambuf request;
std::ostream os(&request);
os << "Client";
boost::system::error_code error;
auto bytes_transferred = socket_.send_to(request.data(), peer, 0, error);
std::cout << "Client sent: " << bytes_transferred << " bytes"
" with " << error.message() << std::endl;
}
示例3: echo
void session::echo(std::vector<uint8_t> const& request)
{
auto reply = request;
socket_.send_to(boost::asio::buffer(request), endpoint_);
std::size_t reply_length = socket_.receive_from(boost::asio::buffer(reply), endpoint_);
if (reply_length != request.size())
throw std::logic_error("Different size of reply and request");
if (reply != request)
throw std::logic_error("Different data value of request and reply");
}
示例4: SendPacket
void SendPacket(const P &packet) {
const ScopeLock protect(mutex);
socket.send_to(boost::asio::buffer(&packet, sizeof(packet)),
endpoint, 0);
}
示例5: SendPacket
bool SendPacket(const P &packet) {
boost::system::error_code ec;
return socket.send_to(boost::asio::buffer(&packet, sizeof(packet)),
endpoint, 0, ec) == sizeof(packet) && !ec;
}