简体   繁体   中英

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.

-With local network's IP I can connect to it only when the client app is runned on the same computer than the server.

-With public IP nothing can connect to the server.

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 . I tried with port 1507 first then tried with port 80 but it didn't change anything

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? If you can't connect probably is router port redirection or access is blocked by firewall.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM