File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes How to implement HTTP connection time out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "How to implement HTTP connection time out" Watch "How to implement HTTP connection time out" New topic
Author

How to implement HTTP connection time out

Aparna Bhure
Greenhorn

Joined: Oct 30, 2007
Posts: 12
Hi All,

I would like to implement an HTTP connection timeout.

I am working on a application which uses HTTP connection, but the problem here is that the response from server is late... I want to create a timeout against HTTP request such that if response doesn't come within sec then the connection should get closed.

Please let me know how I can implement this.

Code is like:

HttpConnection connection = null;
connection = (HttpConnection) Connector.open(getURL(), Connector.READ);
int responseCode = connection.getResponseCode();

I am receiving response code almost after 2-3 sec.. and sometimes 1-2 mins too, which makes my application hang.

I want to create a timeout for such situation, Please let me know how I can implement.. "connection" variable is a local variable.

Thanks,
Regards,
Aparna
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1473
    
    6

j2me apis does not have any connection timeout feature, except on blackberry where you can use a deviceside=true parameter with a timeout value. But that is also works properly on blackberry os version 4.6 or higher.


Swastik
Peter Miklosko
Ranch Hand

Joined: May 26, 2009
Posts: 76
@Aparna I guess you trying to connect without use of Threads. Have look on this chapter 10, from Beginning J2ME: From Novice to Professional, for general idea how to tackle this problem
 
Consider Paul's rocket mass heater.
 
subject: How to implement HTTP connection time out