Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost Asio tcp::resolver: service not found

I'm trying to create an HTTP client using Boost Asio. I copied the sync client example from asio, compile, then run. Unfortunately, on my logs, it shows Service not found. When I traced the code, I found it that it is thrown 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 anybody explain why it is throwing service not found or on how can I solve this?

like image 985
neztreh Avatar asked Jul 11 '11 09:07

neztreh


1 Answers

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

On a unix-like OS, this would mean the line http 80/tcp is missing from /etc/services, I am able to reproduce the error on Linux by commenting that line out.

If the OS cannot be configured to use services, you may use any service "" in the resolver, and specify the port number explicitly when creating the endpoint object for the connect call:

tcp::endpoint connectionEndpoint(endpoint_iterator->address(), 80);
boost::system::error_code ec;
socket.connect(connectionEndpoint, ec);
like image 136
Cubbi Avatar answered Oct 29 '22 10:10

Cubbi