C++ boost.asio server and client connection undersanding
- by Edgar Buchvalov
i started learning boost.asio and i have some problems with undersanding tcp connections. There is example from official boost site:
#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::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 13));
for (;;)
{
tcp::socket socket(io_service);
acceptor.accept(socket);
std::string message = make_daytime_string();
boost::system::error_code ignored_error;
boost::asio::write(socket, boost::asio::buffer(message),
boost::asio::transfer_all(), ignored_error);
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
there is question, why if i want to connet to this server via client i have t write:
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(host_ip, "daytime"); //why daytime?
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;
why daytime?, what it meant and where it is inicialized in server, or i just doesn't missed somefing?
there is full client code : www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/tutorial/tutdaytime1.html
thanks for explanation in advance