Can a Blackberry HTTP request log out immediately if there is no connection?

I have an HTTP connection open

HttpConnection c = (HttpConnection)Connector.open(url);

      

where url

is one of:

  • http://foo.bar;deviceside=false

  • http://foo.bar;deviceside=false;ConnectionType=mds-public

  • http://foo.bar;deviceside=true;ConnectionUID=xxxxxxx

  • http://foo.bar;deviceside=true;interface=wifi

Is there a way to cause an immediate request error if the connection cannot be established because the device is not connected to the network? One way or another, in many cases takes from a minute to a timeout (especially the first call to obtain information from the network: c.getResponseCode()

)

Edit: I mean a bug. In one case, Wi-Fi in particular, it will sit for a few minutes if Wi-Fi is not turned on before the time expires and I want it to stop immediately.

+1


source to share


4 answers


I am using the RadioInfo class to check if there is a connection and if the radio is on before trying to establish a connection. Then you can simply display a message to the user, or turn on the radio (if turned off) before trying to connect, greatly improves the user experience.

Try using:



if (RadioInfo.getState() == RadioInfo.STATE_OFF)
OR
if (RadioInfo.getSignalLevel() == RadioInfo.LEVEL_NO_COVERAGE)

      

To check the connection status before connecting.

+6


source


I am putting my messages on stream to timeout faster. Make sure your "PostThread" catches all exceptions (and keeps them).

public byte[] post(String url, byte[] requestString){
    PostThread thread=new PostThread(url, requestString);

    synchronized(thread){
        try{
            thread.start();
            thread.wait(TIMEOUT);
        }catch(Throwable e){

        }//method
    }//synch

    if (thread.isAlive()){
        try{
            thread.interrupt();
        }catch(Throwable e){

        }//method
        D.error("Timeout");
    }//endif

    if (thread.error!=null) D.error(thread.error);
    if (thread.output!=null) return thread.output;
    throw D.error("No output");
}//method

      



There is also a parameter ConnectionTimeout

that I have not tested: for examplesocket://server:80/mywebservice;ConnectionTimeout=2000

+1


source


Cannot be specified programmatically. This can be annoying, but a connection to a mobile device, especially a BlackBerry, usually goes through several different networks and gateways before reaching the target server: wireless-> Carrier APN-> Internet-> BES (possibly) → foo. bar, so a large timeout is built in to account for possible delays at any of these points.

You can control the default connection timeout to the BES / MDS server (or in JDE, from the MDS \ config \ rimpublic.property file), but that probably won't help you.

0


source


It would be better to have a timeout check from another thread, because this will happen even when the connection is established, say the network latency is very high, so you don't want the user to wait so long for a thing.

So in this case there is a check from another thread if the current time minus the time entered to initiate the connection is greater than your set time, close the connection using connection.close ()!

0


source







All Articles