Не удается создать соединение TCP / IP через Интернет - PullRequest
0 голосов
/ 11 октября 2019

Проблема с переадресацией TCP / IP и PORT

  1. Я отключил Брандмауэр
  2. setup DMZ для моего локального IP
  3. запустил консольное приложение C #, которое прослушивает входящие соединения через порт 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
попытался подключиться к серверу с помощью другого приложения (КЛИЕНТА) с использованием общедоступного 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

Клиент выбросил:

System.Net.Sockets. SocketException: «Попытка подключения не удалась, потому что подключенная сторона не ответила должным образом через определенный промежуток времени, или не удалось установить соединение, так как подключенный хост не смог ответить 197.119.200.25:8659'

Итак, мой вопроспочему мое серверное приложение недоступно по общему IP-адресу компьютера?

Я не знаю, блокирует ли это порты моего интернет-провайдера, или у меня возникла другая проблема, о которой я не знаю!

...