Boost Asio tcp :: resolver: service not found

I am trying to create an HTTP client using Boost Asio. I copied the sync client example from asio, compiled, and then launched. Unfortunately, my logs show that the Service was not found. When I traced the code, I found that it was derived from the following code:

boost::asio::io_service io_service;
// Get a list of endpoints corresponding to the server name.
tcp::resolver resolver(io_service);
//->if i removed the http, it has no error
tcp::resolver::query query("host.com", "http");
//->This part throws the service not found
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;

Can someone explain why it throws the service is not found or how can I solve it?

+5
source share
1 answer

This means that the OS does not know which port number corresponds to the TCP service named "http".

unix- , /etc/services http 80/tcp, Linux, .

, "" :

tcp::endpoint connectionEndpoint(endpoint_iterator->address(), 80);
boost::system::error_code ec;
socket.connect(connectionEndpoint, ec);
+6

All Articles