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(); }
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; }
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"); }
void SendPacket(const P &packet) { const ScopeLock protect(mutex); socket.send_to(boost::asio::buffer(&packet, sizeof(packet)), endpoint, 0); }
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; }