예제 #1
0
파일: example.cpp 프로젝트: sfff/example
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");
}
예제 #2
0
파일: main.cpp 프로젝트: CCJY/coliru
void Server::receive() {
    Peer peer;
    boost::system::error_code error;
    auto bytes_transferred =
      socket_.receive_from(boost::asio::buffer(recv_buffer_), peer, 0, error);
    std::cout << "Server received " << bytes_transferred << " bytes"
                 " from " << peer
              << " with " << error.message() << std::endl;
    if (!error) {
      std::cout << "  >> ";
      std::cout.write(recv_buffer_.data(), bytes_transferred);
      std::cout << std::endl;
    }
    receive();
}