简体   繁体   English

无法从另一台PC连接到我的C#服务器

[英]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.

相关问题 无法从Windows PC连接任何指定的MySQL主机c#应用程序,尝试在Ubuntu 16.04服务器上连接mysql服务器 - unable to connect any of the specified MySQL host c# application from windows pc trying to connect mysql server on Ubuntu 16.04 server 无法从c#代码连接到我的Tfs服务器 - Unable to connect to my Tfs server from c# code 无法使用C#连接到其他计算机的mysql服务器? - unable to connect to other machine's mysql server using C#? 无法从C#连接到MySQL,但可以从其他应用程序连接到MySQL - Unable connect to MySQL from C# but possible from other apps C# Winforms 使用 TcpListener 我无法从局域网上的其他设备连接到服务器 - C# Winforms using TcpListener I can't connect to server from other devices on my LAN 连接到其他PC上的SQL Server - Connect to SQL Server on other PC 无法从C#应用程序连接远程服务器mysql数据库 - Unable to connect remote server mysql database from C# application 无法从 C# 应用程序连接到远程 SQL Server 实例 - Unable to connect to remote SQL Server Instance from C# Application 无法从Windows应用程序C#连接到SQL Server数据库 - unable to connect to sql server database from windows application c# 无法连接到远程服务器C# - Unable to connect to the remote server C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM