HttpConnection timeout property -- Is it possiblee to set it (or at least read it)?
Question as titled.
I am developing a server-client application.
All http connections are made to run on a background thread.
Here's a code snip.
try {
hc = (HttpConnection) Connector.open(connaddr, Connector.READ_WRITE, true); // hc is of class HttpConnection
} catch (InterruptedException timeout) {
System.err.println("Timeout detected");
} finally {
hc.close();
}
I believe that this code should work fine. But is there a way I can really specify the timeout property? Or it would be great if I can read the timeout property at least.
Thanks all.
Re: HttpConnection timeout property -- Is it possiblee to set it (or at least read it
sorry, i don't think it can work..
when the programe is blocked in "Connector.open", you call the conn.close, it doesn't work. in my opinion, the only way is to kill the thread. but this way can only be supported in cldc1.1.
Re: HttpConnection timeout property -- Is it possiblee to set it (or at least read it
Try this may this helps you
Timer timer = new Timer ();
MyTimerTask mTT = new MyTimerTask ();
boolean connectionNotEstablished = true;
private class MyTimerTask extends TimerTask {
public final void run() {
// your body goes here
if (connectionNotEstablished) {
// close all opened streams and the connection if they are not null...
callOfflineTask();
}
}
// another Class Extends Thread
private void makeConnection (String url) throws IOException {
try {
// here goes ur connection establishment
timer.schedule(mTT, timeout) ; // ur desired timeout.
// and the tasks afterwards..
setConnectionNotEstablished(false); // if connection establishes.
// some other tasks.
// Open Connection
} catch (Exception e) {
//Cancel Timer
throw new IOException(e.getMessage());
} finally {
// close all opened streams and the connection if they are not null...
}
}
public void run () {
try {
makeConnection (URL);
}
catch (IOException ioe) {
mTT.cancel();
callOfflineTask();
}
}
Thanks
Ravi