// see https://developer.android.com/reference/java/net/Socket#setSoTimeout(int) try { mSocket.setSoTimeout(10*1000); // OR mSocket.connect(address, 10*1000); } catch (SocketTimeoutException e) { // on timeout }