• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with HTTP connection and threads in J2ME

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have one thread that does a HTTP connection with the server. In some cases, the connection is established to the server and request is sent to server, then connection hangs. I cannot check the response code since the response doesn't return back. In this case, my app also hangs on the progress bar screen. Is there any way to handle timeouts in this circumstances? How do I know if the response object doesn't return back?
[ July 28, 2005: Message edited by: Rita Smith ]
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rita
We know that http is a request/response protocol. So when u send a request, surely u will get a response. May be success or failure. In case of success it returns HTTP/1.0 200 OK. There are other codes for failure. say, HTTP/1.0 401 Unauthorized. So first parse the response code. Go through the API- Interface HttpConnection. U may use public int getResponseCode() or public String getResponseMessage() for parsing. Let me know what happens!!!

Debojit
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am working on BlackBerry handhelds and i faced similar problem.
The solution to this problem i found was i contineously sent noop data to the server, and it was done then. May be it will help u too !

Thanks,
Abhijit Chandekar
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What device are you using?
In which version of HTTP does your server reply (1.1)?
Is your server generating Reason-Phrases (e.g. "OK", "No Content")?

We are having trouble with the Nokia 6230i, using getReasonCode()
to connect, transmit and receive. I guess the method on the Nokia 6230i
cannot cope with missing Reason-Phrases, as our server is not generating
these ...

A server of ours which generates the Reason-Phrases works fine with the
client software on the 6230i.

Perhaps you are having a similar problem.

Stuart
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Rita this trouble is common when the place you are does not have a good coverage, but when you open the HttpConnector it has a constructor when you can especify a default time out So when the application doesn't recieve any information from the page it brokes the connection and continue with the other proccess you have.

Grettings.

Armando M.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

we have similar problems. Sometimes, when we call openinputstream, we don't receive anything and even after a minute (Nokia S60 - 6630, 6600...), the connection hasn't timedout).

When this happens, we start another thread and redo a request. Sometimes this works, sometimes it doesn't. I've heard that adding a sleep of 1000ms as the first line of code in the run method of the thread could help. We are trying this now.

Regarding the timeout parameter of the open method: is it just for the open method or is the timeout value valid for all communications for that connection (like openinputstream for example) ?
 
Armando Miranda
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, everybody, I show you the constructor I use for the communications.
conexion = (HttpConnection)Connector.open(url, Connector.READ_WRITE, true);

As you can see the parameter "true" after READ_WRITE, means that if the handset doesn't receive anything It brokes by itself. It takes about 2 minutes and into the 2 minutes the application goes freze, It's the prize of this trouble.

Regards.

Armando M.
 
Debojit Nag
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Miranda
Your code
conexion = (HttpConnection)Connector.open(url, Connector.READ_WRITE, true);
may not work in some cases where the server don't give WRITE access permission and then this will throe an exception. Better to open it in READ mode. What u think?

Debojit
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic