Last active
February 13, 2018 14:29
-
-
Save edouarda/8fd882f03549382b34633af557dc6d81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/asio.hpp> | |
#include <iostream> | |
int main(int, char **) | |
{ | |
boost::asio::io_context context; | |
const boost::asio::ip::udp::endpoint ep{boost::asio::ip::udp::v4(), 8080}; | |
boost::asio::ip::udp::socket s{context, ep}; | |
while (true) | |
{ | |
boost::system::error_code ec; | |
std::array<std::uint8_t, 1024> discard_buffer; | |
while (!ec) | |
{ | |
boost::asio::ip::udp::endpoint peer; | |
auto l = s.receive_from( | |
boost::asio::buffer(discard_buffer), peer, 0, ec); | |
if (ec) break; | |
s.send_to(boost::asio::const_buffer{discard_buffer.data(), l}, peer, | |
0, ec); | |
} | |
} | |
s.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment