title: Why can't I connect to my server using my public IP?
body: <p>I have a server program and a client program. While developing the program I run the server and the client on the same machine for convenience. The server starts listening to incoming connections using these lines:</p>
  
  <pre><code>var listener = new TcpListener(IPAddress.Any, 7070);
  listener.Start();
  </code></pre>
  
  <p>The client connects to the server using these lines (simplified):</p>
  
  <pre><code>var client = new TcpClient(AddressFamily.InterNetwork);
  client.Connect(IPAddress.Loopback, 7070);
  </code></pre>
  
  <p>I use <code>IPAddress.Loopback</code> because I run the programs on the same machine. But, knowing that the server and the client won't be necessarily run on the same machine in the future, I changed it to my public IP from <a href="http://icanhazip.com" rel="nofollow">http://icanhazip.com</a> (<code>IPAddress.Parse(...)</code>). Because of that the client was unable to connect to the server on the same machine with the exception <code>No connection could be made because the target machine actively refused it &lt;my public ip:7070&gt;</code>.</p>
  
  <p>I tried disabling my firewall but it's still not working. Why is the server refusing the connection? Didn't I specifically tell it to listen to <strong>all</strong> interfaces with <code>IPAddress.Any</code>?</p>
  
  <p>Why does that happen and how do I fix it?</p>