title: C# TCP Socket Client refuses connection
body: <p>Here is my Server</p>
  
  <p>When using multiple different port checking tools on the internet I get connections on my server, demonstrating that my ports are open</p>
  
  <p><a href="http://www.infobyip.com/tcpportchecker.php" rel="nofollow noreferrer">http://www.infobyip.com/tcpportchecker.php</a></p>
  
  <p><a href="http://www.yougetsignal.com/tools/open-ports/" rel="nofollow noreferrer">http://www.yougetsignal.com/tools/open-ports/</a></p>
  
  <p><a href="http://ping.eu/port-chk/" rel="nofollow noreferrer">http://ping.eu/port-chk/</a></p>
  
  <p><a href="http://ping.eu/port-chk/" rel="nofollow noreferrer">http://ping.eu/port-chk/</a></p>
  
  <p><a href="https://i.stack.imgur.com/PBbxZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PBbxZ.png" alt="Multiple successful connections"></a></p>
  
  <pre><code>static void Main(string[] args)
  {
      IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
      IPAddress ipAddress = ipHostInfo.AddressList[0];
      IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 10897);
      Console.WriteLine("Server Start");
  
      Socket listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
      listener.Bind(localEndPoint);
      listener.Listen(10);
      while (true)
      {
          Console.WriteLine("Waiting for a connection...");
          Socket handler = listener.Accept();
          Console.WriteLine(handler.RemoteEndPoint);
          handler.Shutdown(SocketShutdown.Both);
          handler.Close();
      }
  }
  </code></pre>
  
  <p>Here is my client code</p>
  
  <pre><code> static void Main(string[] args)
   {
       IPEndPoint ip = new IPEndPoint(IPAddress.Parse("MY IP HERE"), 10897);
       Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
       server.Connect(ip);
   }
  </code></pre>
  
  <p>I get this error everytime, I have tried multiple different attempts from the client side using System.Net.Sockets.TcpClient and sockets and everytime I get connection refused so it appears to be some issue with my client since my server receives connections from port checkers
  <a href="https://i.stack.imgur.com/zru4z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zru4z.png" alt="Error"></a></p>
  
  <p>I have read through dozens of other socket topics but all of the issues have to do with the server and not the client, I no idea what is wrong can somebody help me?</p>
  
  <p>EDIT:
  I can connect via localhost (127.0.0.1) but not from my public IP</p>