I cant get my error message. When the connection is OK, i can see the message "Connection OK". But when i want to connect to a "bad" ip server, i cant see the message "Bad Connection". Why is this? I waited until 2 minutes (i read connection has 2 minutes timeout) but nothing happens.
What i want to do is to cancel my connection and show a message is connection is bad or i cant get information from server.
public void run() {
try {
conn = (HttpConnection) Connector.open(URL);
int status = conn.getResponseCode();
if (status != HttpConnection.HTTP_OK) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
mainScreen.add(new RichTextField("Bad Connection"));
}
});
conn.close();
return;
}
InputStream contentIn = conn.openInputStream();
byte[] data = new byte[400];
int length = 0;
StringBuffer raw = new StringBuffer();
while (-1 != (length = contentIn.read(data))) {
raw.append(new String(data, 0, length));
str = raw.toString();
conn.close();
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
mainScreen.add(new RichTextField("Connection OK"));
}
});
}
} catch (Exception e) {
}
}