I am trying to connect a socket to a nonexistent server, and I really don’t understand why the exception does not occur.
Here is my code:
public class TestSocket extends Activity { private static final String TAG = "TestSocket"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); BasicThread t = new BasicThread(); t.start(); } class BasicThread extends Thread { @Override public void run() { Log.d(TAG, "Before"); try { new Socket("42.42.42.42", 12345); Log.d(TAG, "Connected"); } catch (Exception e) { Log.d(TAG, "Exception"); } Log.d(TAG, "After"); } } }
I also tried to use my own IP address while Wireshark was working, and first I got [SYN] from Android to my computer, and then [RST, ACK] from my Android computer (because it doesn’t listen to anything on this port), but I still don't get exceptions on Android.
Also Im testing on a physical phone (Nexus S), and I have internet permission in my manifest.
Why am I not getting an Exception ?
Edit:
More precisely, the conclusion that I get is
D/TestSocket(17745): Before D/TestSocket(17745): Connected D/TestSocket(17745): After
(not Exception )
source share