简体   繁体   中英

I can't connect to the server (C#)

I have Server and Client scripts in C# programming language. When I create server on my computer and from another computer I'm trying to connect to the server it says:

an existing connection was forcibly closed by the remote host

It's happening when I change the IP of the server to 0.0.0.0 (IPAdress.Any)

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

It' happening when I change the IP of the server to IPv4 which is 10.0.0.6 (On the ipconfig - IPv4).

Also I turned off the Firewall, And I opened port (11000) on website of the router.

I put in the client the public IP address of the server (which is on whatismyip.com).

The program works perfectly when it is on the local network (I mean when the both computers have the same network).

Scripts:

Does anyone know how to solve it?

First of all, check to make sure your server is actively listening on the TCP port you expect. If it is a Windows machine, from the command line try:

netstat -ano | findstr ***LISTENINGPORT***

In your case I'm guessing you should be listening on 11000.

If so, on the client side, let me know exactly where your code is breaking. I'm assuming for now it's this:

sender.Connect(new IPEndPoint(IPAddress.Parse(ip), 11000));

.. and also run a WireShark capture on the client machine.

There are plenty of quick start-up guides - basically this will allow you to see the request your Client is making across the network, & see if a connection (if any) is being established on the server.

If you ARE making a connection, then it is just being closed for another reason, then you have a code issue. If NOT, then you have a network/configuration issue. This should help you make progress.

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