I have an android app which works when I am connected to wifi, but not when I am connected through 4G. To clarify, it works when I am connected to any wifi internet connection, not the network my server is on. My manifest file contains:
<uses-permission android:name="android.permission.INTERNET" />
and the offending line is:
new Socket(InetAddress.getByName("mydomain.com"), XXXX);
which hangs and then gives me this error:
java.net.ConnectException: failed to connect to mydomain.com/XXX.XXX.XXX.XXX (port XXXX): connect failed: ETIMEDOUT (Connection timed out)
which I printed to logcat. I do not think it is a DNS problem because I successfully found the IP address with
System.out.println("Server IP:" + InetAddress.getByName("mydomain.com").toString());
I am running this on my Samsung S III phone. Again, it works fine when I am connected to wifi or when I run it in an emulator, but the client Socket times out when my internet connection is 4G. Any ideas why this would happen?