I’m trying to follow the steps provided in this page
http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/tutorial/tutdaytime1.html
However, at some point the code does not compile, and gives me the specified error. I can’t understand what kind of conflict it is. The object tcpsock doesn’t seem to be correctly created. Please check my code:
io_service io_tcp;
tcp::resolver resolverObject(io_tcp);
tcp::resolver::query queryObject(argv[1], "daytime");
tcp::resolver::iterator endpoint_iterator = resolverObject.resolve(queryObject);
tcp::resolver::iterator end; //default constructor is end iterator
tcp::socket tcpsock(io_service);
boost::system::error_code socketError = boost::asio::error::host_not_found;
while (socketError && endpoint_iterator != end)
{
//Apparently, the object isn't created correctly
tcpsock.close(); //error happenes here
tcpsock.connect(*endpoint_iterator++, socketError); //error happenes here too
}
if (socketError)
throw boost::system::system_error(socketError);
Thank you for any efforts.
You are initializing
tcpsockwith the typeio_service, not with the variableio_tcp.