Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using HttpConnection in MIDP

 
Glenn Castro
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to use one HttpConnection for sending multiple request, in other words, the connection is always alive?

In my application, I can send my login request. The succeeding request displays this exception:

java.lang.IllegalStateException: Write attempted after request finished
at com.sun.midp.io.j2me.http.Protocol.writeBytes(+16)
at com.sun.midp.io.BaseOutputStream.write(+52)
at java.io.OutputStream.write(+8)
 
Glenn Castro
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already solved the problem
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Care to share your solution?
 
Mateus Bicalho
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone else did this?

I'm having the same problem... would appreciate if someone could give any info on this please.
 
Glenn Castro
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Well, to avoid the problems of having IllegalStateException, I created new connection in every request and close it afterwards. I checked the Protocol class in the com.sun.midp.io.j2me.http package and I think that HttpConnection is designed that way (opens the connection -> send request -> getresponse -> close the connection). Once a request is sent, it sets the requestFinished (on the Protocol class) variable to true, thus throws an IllegalStateException.

Just a suggestion: Use one connection per request. Avoid reusing connection/keep alive connection.

Hope that it helped you guys!
[ November 10, 2004: Message edited by: Glenn Castro ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic