title: boost asio: "host not found (authorative)"
body: <p>I am making a program for school in which two programs communicate with each other.
  So far I have not been able to connect the two programs.
  Whenever I try to connect to localhost:8888 or 127.0.0.1:8888, the error "Host not found (authoritative)" occurs.</p>
  
  <p>So far my code is this:</p>
  
  <h3>Connection.cpp</h3>
  
  <pre><code>Connection::Connection(std::string Arg) {
      try
      {
          tcp::resolver resolver(io_service);
          cout&lt;&lt;Arg&lt;&lt;endl;
          tcp::resolver::query query(Arg, "daytime");
          tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
          tcp::resolver::iterator end;
  
          tcp::socket socket(io_service);
          socket_p = &amp;socket;
          boost::system::error_code error = boost::asio::error::host_not_found;
          while (error &amp;&amp; endpoint_iterator != end)
          {
             socket.close();
             socket.connect(*endpoint_iterator++, error);
          }
          if (error)
             throw boost::system::system_error(error);
      }
      catch (std::exception&amp; e)
      {
          std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
      }
  }
  void Connection::Receiver() {
      try{
          for (;;)
          {
              boost::array&lt;char, 128&gt; buf;
              boost::system::error_code error;
  
              size_t len = socket_p-&gt;read_some(boost::asio::buffer(buf), error);
  
              if (error == boost::asio::error::eof)
                  break; // Connection closed cleanly by peer.
              else if (error)
                  throw boost::system::system_error(error); // Some other error.
  
              std::cout.write(buf.data(), len);
          }
      }
      catch (std::exception&amp; e)
      {
          std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
      }
  } 
  </code></pre>
  
  <p>In case this helps, I use fedora.</p>
  
  <p>EDIT:
  the full code can be found here:
  <a href="http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/tutorial/tutdaytime1.html" rel="noreferrer">http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/tutorial/tutdaytime1.html</a>
  i tried to make it OOP (not sure if i did a good job)</p>