Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Changing network timeout duration?

Hi,

 

I've found that with midlets, we can't change the timeout duration for network requests, we're forced to use whatever the phone's default timeout is (on the 8130 this seems to be 180 seconds). 

 

Is there really no way to change the timeout?

 

If not, can I mix RIM specific network connection open/close methods in my midlet? I ask because I saw that the RIM specific classes allow you to change the timeout to something smaller.

 

Thanks

Developer
Posts: 16,494
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Changing network timeout duration?

see
http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=843&query.id=1294...

"The default timeout for a socket connection is also 2 minutes. You can control the timeout by using the SocketConnectionEnhanced interface and setting the READ_TIMEOUT option."

(actually i found the thread by putting "timeout" into the search window. would be more convienient for you to do the same next time)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Changing network timeout duration?

I agree Simon, a little searching goes a long way....

 

You might also find the following KB article useful.

 

How To - Control the connection timeout for TCP connections through BlackBerry Mobile Data System Connection Service
Article Number: DB-00526

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/How_To_...

 

I use this method because it is available in OS 4.0, but only for MDS connections. 

Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Re: Changing network timeout duration?

I'm not using MDS, so the KB article solution won't work for me sadly.

 

SocketConnectionEnhanced is a BB specific interface class, which lists known implemented classes as:

 

    SSL30Connection, TLS10Connection

so would I need to use one of those two for my connections? Is that safe to mix with a midlet?

Thanks

BlackBerry Development Advisor
Posts: 14,947
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Changing network timeout duration?

SocketConnectionEnhanced can be used in a MIDlet.  You can use it with a SocketConnection as well, just cast the SocketConnection to a SocketconnectionEnhanced.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Re: Changing network timeout duration?

Hi Mark,

 

Currently I'm making a connection like:

 

    import javax.io.microedition.io.Connector;

 

    String postURL = "..";
    HttpConnection conn = (HttpConnection)Connector.open(postURL); 

 

I try to cast conn like:

 

    SocketConnectionEnhanced c2 = (SocketConnectionEnhanced)conn;
    c2.setSocketOptionEx(SocketConnectionEnhanced.READ_TIMEOUT , 10000);
                

but that throws an exception. Do I have to rewrite my code to SocketConnection  from Connector.open() instead of HttpConnection for the cast to work?

 

Thanks

Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Re: Changing network timeout duration?

Ah actually same thing with SocketConnection, I tried:

  

    SocketConnection conn = (SocketConnection)Connector.open(postURL);
    SocketConnectionEnhanced c2 = (SocketConnectionEnhanced)conn;

but it throws an exception on the cast, what's the right way to do it?

 

Thanks               

BlackBerry Development Advisor
Posts: 14,947
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Changing network timeout duration?

SocketConnectionEnhanced is not meant to be used for HTTP connections.

 

You can cast the object returned from Connector.open as a SocketConnectionEnhanced (assuming you used a URL specifying the socket:// protocol), set the time out and cast this object to something you can read/write to, such as a StreamConnection.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Re: Changing network timeout duration?

Ah ok I'm just making http connections so I guess it won't work for me. The link to the other article you sent me though addresses this I think:

 

"The rationale behind checking the network is that the Connector.open call will require a two minute timeout even if the radio has been turned off. It is best for the application to check the radio status before invoking Connector.open."

 

So I guess that before each time I try calling Connector.open, I just check if there is any service or not, and that should be good enough for my purposes,


Thanks