C# – No connection could be made because the target machine actively refused it–Socket C#

cnetnetwork-programmingsocketstcpclient

Hi guys i'm trying to build a server-client app in c#.it is working on local but i want to work it through internet bu i have this error when i entered my ip:

No connection could be made because the target machine actively refused it

Checked that my firewall is off.

here is my code.i wish you could help..

enter image description here

Best Answer

When testing connectivity there are few simple steps for basic testing.

  • try to ping target machine
  • if target machine is local one, then use 127.0.0.1 address if all other addresses fail
  • disable your firewall
  • check that server service/application is started
  • try to telnet to address and port of that service to see if port is open
  • make sure that no other application is holding the port open. You can do this using netstat utility

In your specific case it looks to me like you are trying to connect to your router rather than machine you are hosting application on. Do ipconfig /all in Command prompt to see all IP address your machine has.

Related Topic