The following gets called with isValid.execute(address)
, I then call isValid.get()
to get the response. However, it hangs and all it's returning is a boolean (true or false),
The bit I use to call the code is:
IsValid isValid = new IsValid();
try {
isValid.execute(addr);
success = isValid.get();
}
catch (Exception e) {
success = false;
}
return success;
IsValid class
public class IsValid extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
Boolean success = false;
try {
SocketAddress sockaddr = new InetSocketAddress(params[0], 80);
// Create an unbound socket
Socket sock = new Socket();
// This method will block no more than timeoutMs.
// If the timeout occurs, SocketTimeoutException is thrown.
int timeoutMs = 2000; // 2 seconds
Logit(TAG,"" + sockaddr.toString());
sock.connect(sockaddr, timeoutMs);
success = true;
}
catch (Exception exc) {
success = false;
}
return success;
}
@Override
protected Boolean onPostExceute(Boolean result) {
Logit(TAG,"IN POST, RESULT IS = "+result);
return result;
}
}