• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Using HttpConnection in MIDP

 
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Care to share your solution?
 
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic