Unable to connect from remote machine

孤街浪徒 提交于 2019-12-05 03:04:05

You need to set it to accept connections from any IP, there is an IPAddress overload function for this:

System.Net.IPAddress.Any

use it instead of 127.0.0.1 and it will fix your problem.

You're listening on 127.0.0.1 which is the loopback address which is a special address that means 'this computer'. This means that you will only accept connections that are made on the same machine as the server is running on.

You need to listen on one (or more) of the server's real ip addresses.

Your problem is that the setting an IP address explicitly when you initialize the TcpListener will only allow it to accept connections from that address. Therefore, putting in the local address of 127.0.0.1 will only accept connections originating from your PC.

The implementation you want to use is as follows:

TcpListener tcpListener = new TcpListener(IPAddress.Any, port);

This will allows connections from any IP address to connect to your program on the specified port.

I think it is your computer (the server) that refuses to connect because 127.0.0.1 is local(-only).

Try this simple overload:

  TcpListener tcpListener = new TcpListener(port);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!