I have had code that has been working fine for almost two years untouched which connects to a server that I created. Suddenly, I can't get the TcpClient to connect any more.
The client that is connecting runs on my Android device (Android Version 6.0).
TcpClient tcpClient = new TcpClient();
bool success = tcpClient.ConnectAsync(ServerIP, Port).Wait(TimeSpan.FromSeconds(5));
if (success)
stream = tcpClient.GetStream();
This task always returns false. I tried using the blocking function tcpClient.Connect()
and it gets a timeout exception.
I even ran the server with Visual Studio attached to see if it receives any sort of connection before disposing of it, but it never receives anything.
Any ideas?
[UPDATE]
I wrote a test application on my computer to try to connect using the same exact code I have written above. It did not connect using the given IP address. But, I changed the IP to the servers local IP and it connected.
With that, I tried connecting with my Android without Wifi and it still did not work.
So what would prevent this from connecting using an actual IP address instead of a local?
[ANSWER]
I tried resetting my router/modem and that did not work. So, I changed the local IP on the server to something else (was using 192.168.0.2, I changed it to 192.168.0.4) and it worked.
I double checked to make sure there was no IP conflicts on my network and all seemed fine, so I am not sure why 192.168.0.2 was causing a failure to connect.
All is good now.