Created
February 13, 2018 15:13
-
-
Save edouarda/e6efb392ee340b7f90bb4500e2ab67d4 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; | |
auto ip = boost::asio::ip::address::from_string("127.0.0.1"); | |
auto ep = boost::asio::ip::tcp::endpoint{ip, 8080}; | |
boost::asio::ip::tcp::acceptor acc{context, ep}; | |
while (true) | |
{ | |
boost::system::error_code ec; | |
auto s = acc.accept(ec); | |
if (ec) | |
{ | |
std::cerr << ec.value() << ec.message() << std::endl; | |
break; | |
} | |
auto t = std::chrono::system_clock::to_time_t( | |
std::chrono::system_clock::now()); | |
std::array<char, 1024> time_buffer; | |
auto err = ::ctime_s(time_buffer.data(), time_buffer.size(), &t); | |
auto len = ::strnlen_s(time_buffer.data(), time_buffer.size()); | |
if (!err) | |
{ | |
boost::asio::write( | |
s, boost::asio::const_buffer{time_buffer.data(), len + 1}, ec); | |
} | |
s.shutdown(boost::asio::socket_base::shutdown_both, ec); | |
s.close(ec); | |
} | |
acc.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment