title: How can I limit a boost asio acceptor to localhost and/or local networks?
body: <p>I am trying to figure out how to limit a tcp socket to localhost. I finally found code that will compile, but it does not accept any connections.</p>
  
  <p>The code accepts connections with endpoint_all, but not with "endpoint_local" variable set with tcp::endpoint(ip::address::from_string("127.0.0.1"),port2);</p>
  
  <pre><code>boost::asio::io_service io_service;
  short port = 9000;
  tcp::endpoint endpoint_all   = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(),port);
  tcp::endpoint endpoint_local = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"),port);
  try
  {
      server s(io_service, std::atoi("9000"),endpoint_all);
  
      io_service.run();
  }
  catch (std::exception&amp; e)
  {
  }
  </code></pre>
  
  <p>Update: I can access the socket via "telnet 127.0.0.1 9000" and "telnet localhost 9000". The actual application in question (PHP XDebug) does not connect to the ip limited endpoint, but does otherwise.</p>
  
  <p>"telnet localhost 9000" give the following error, but does connect. I don't connect have localhost in php.ini, but maybe this message is related. "Connection refused for ::1:"</p>
  
  <p>I think it would be proper to allow connections to ::1: regardless of if this is the bug or not.</p>
  
  <pre><code>Trying ::1...
  telnet: connect to address ::1: Connection refused
  Trying fe80::1...
  telnet: connect to address fe80::1: Connection refused
  Trying 127.0.0.1...
  Connected to localhost.
  </code></pre>