Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: CCJY/coliru
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;      
}
Ejemplo n.º 3
0
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");
}
Ejemplo n.º 4
0
 void SendPacket(const P &packet) {
   const ScopeLock protect(mutex);
   socket.send_to(boost::asio::buffer(&packet, sizeof(packet)),
                  endpoint, 0);
 }
Ejemplo n.º 5
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;
 }