title: C++ boost::asio no connection could be made because the target machine actively refused it
body: <p><em>This is not a duplicate! (This is not about UDP, it is TCP. This is not C#, Python or whatever, it is C++)</em></p>
  
  <p>I get the error described in the title if I try to connect through my external IP. However, it works via "localhost" or "127.0.0.1" (I am running client.exe and server.exe on the same machine). This code was copied from an example and I made minor changes.</p>
  
  <p>EDIT: I gave Firewall permission to both executable files. Still, the problem persists.</p>
  
  <p>Server:</p>
  
  <pre><code>#include &lt;ctime&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/asio.hpp&gt;
  
  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(&amp;now);
  }
  
  int main()
  {
    try
     {
      boost::asio::io_service io_service;
  
      tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 62000));
  
  
      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), ignored_error);
      }
    }
    catch (std::exception&amp; e)
    {
       std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
    }
  
    return 0;
   }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/array.hpp&gt;
  #include &lt;boost/asio.hpp&gt;
  
  using boost::asio::ip::tcp;
  
  int main(int argc, char* argv[])
  {
    try
    {
      boost::asio::io_service io_service;
      tcp::resolver resolver(io_service);
      tcp::resolver::query query("localhost", "62000");
      tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
  
      tcp::endpoint endpoint = *endpoint_iterator;
      std::cout &lt;&lt; endpoint &lt;&lt; "\n\n";
  
      tcp::socket socket(io_service);
  
      boost::asio::connect(socket, endpoint_iterator);
  
      for (;;)
      {
        boost::array&lt;char, 128&gt; buf;
        boost::system::error_code error;
  
        size_t len = socket.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;
    }
  
    std::cout &lt;&lt; "\n\n";
    system("pause");
    return 0;
  }
  </code></pre>