[英]Unable to connect to my C# server from an other pc
I have a server and a client app, the server throws no exception and seems to listen properly but the clients aren't able to connect for some reasons, I tried with both local network and public IP. 我有一个服务器和一个客户端应用程序,该服务器没有异常,并且似乎可以正确监听,但是由于某些原因,客户端无法连接,因此我尝试使用本地网络和公共IP。
-With local network's IP I can connect to it only when the client app is runned on the same computer than the server. -使用本地网络的IP,仅当客户端应用程序在与服务器相同的计算机上运行时,我才能连接到该IP。
-With public IP nothing can connect to the server. -使用公共IP,无法连接到服务器。
However in both cases when the connection fails, it behaves always the same : waits for aproximately 5-10 seconds and then throws System.Net.Socket.SocketException
. 但是,在两种情况下,当连接失败时,它的行为始终相同:等待大约5到10秒,然后抛出
System.Net.Socket.SocketException
。 I tried with port 1507 first then tried with port 80 but it didn't change anything 我先尝试使用端口1507,然后尝试使用端口80,但它没有改变任何内容
Server 服务器
IPAddress adress = IPAddress.Parse(MyIp);
TcpListener listener = new TcpListener(adress, 80);
listener.Start();
TcpClient Client = await listener.AcceptTcpClientAsync();
Client 客户
TcpClient client = new TcpClient();
client.ConnectAsync(IPAddress.Parse(MyIp), 80).GetAwaiter().GetResult();
I don't understand where the problem comes from, is it coming from my code or not? 我不明白问题出在哪里,是我的代码引起的吗? If not the what could it be and how could I fix it?
如果不是,那是什么,我该如何解决?
Have you tried Telnet from outside network on specific port? 您是否在特定端口上从外部网络尝试过Telnet? If you can't connect probably is router port redirection or access is blocked by firewall.
如果无法连接,可能是路由器端口重定向或防火墙阻止了访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.