Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CLIENT
- #pragma warning(disable : 4996)
- #include <iostream>
- #include <string>
- #include <boost/asio.hpp>
- using boost::asio::ip::tcp;
- int main(int argc, char* argv[])
- {
- try
- {
- if (argc != 2)
- {
- std::cerr << "Usage: daytime_client <host>" << std::endl;
- return 1;
- }
- tcp::iostream s(argv[1], "daytime");
- std::string line;
- std::getline(s, line);
- std::cout << line << std::endl;
- }
- catch (std::exception& e)
- {
- std::cout << "Exception: " << e.what() << std::endl;
- }
- return 0;
- }
- //SERVER
- #pragma warning(disable : 4996)
- #include <ctime>
- #include <iostream>
- #include <string>
- #include <boost/asio.hpp>
- using boost::asio::ip::tcp;
- std::string make_daytime_string()
- {
- using namespace std; // For time_t, time and ctime;
- time_t now = time(0);
- return ctime(&now);
- }
- int main()
- {
- try
- {
- boost::asio::io_service io_service;
- tcp::endpoint endpoint(tcp::v4(), 13);
- tcp::acceptor acceptor(io_service, endpoint);
- for (;;)
- {
- tcp::iostream stream;
- acceptor.accept(*stream.rdbuf());
- stream << make_daytime_string();
- }
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement