0

Problem with TCP/IP and PORT Forwarding

  1. I disabled the Firewall
  2. setup DMZ to my local IP
  3. ran a C# console app which listens for incoming connections from port 8659 (SERVER):
static void Main(string[] args)
{
    // port to listen to
    int connPort = 8659;
    // the  local endPoint
    var localEP = new IPEndPoint(IPAddress.Any, connPort);
    // creating the socket
    using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
    {
        // binding the socket to the local endPoint
        socket.Bind(localEP);
        // listening for incoming connections
        socket.Listen(10);
        // logging
        Debug.WriteLine("waiting for client ...");
        // grab the first client
        var client = socket.Accept();
        // logging
        Debug.WriteLine("client connected !");
        var jsonContent = "this is json test";
        // sending the json content as a json response
        client.Send(Encoding.ASCII.GetBytes("HTTP/1.1 200 OK\n" +
            "Content-Type: text/plain\n" +
            $"Content-Length: {jsonContent.Length}\n" +
            "\n" + jsonContent));
    } // end of using
    Console.ReadLine();
} // end of main
  1. tried to connect to the server with another app (CLIENT) using the public IP:
static void Main(string[] args)
{
    var host = Dns.GetHostEntry(Dns.GetHostName());
    // the ip address of the interface connected to internet
    var ip = host.AddressList[1];
    // my public IP ( dynamic ) not yet static, just a test
    var ServerIP = IPAddress.Parse("197.119.200.25");
    // the server endpoint
    var serverEP = new IPEndPoint(ServerIP, 8659);
    // the endpoint to use to connect to the server
    var localEP = new IPEndPoint(ip, 8658);
    // creating the socket
    var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    // bind the socket to the endpoint
    socket.Bind(localEP);
    // connect to the server endpoint
    socket.Connect(serverEP);
} // end of mainc

Client threw:

System.Net.Sockets.SocketException: 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 197.119.200.25:8659'

So my question is why isn't my server app reachable by the machine's public IP?

I don't know if it's my ISP blocking Ports or I have another problem that I'm not aware of!

AbdelAziz AbdelLatef
  • 3,650
  • 6
  • 24
  • 52

0 Answers0