• 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

httpConnection limted?

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine to get data from localhost with GET. But when I try several times in row Im getting this error : "java.io.IOException: exceeded the configured maximum number of connections" usaly on the fifth time. Why is that. Here is my code

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this code. I have not tried it. I think it's better.
private void httpConnection(String url){


HttpConnection httpConnection = null;
DataInputStream din = null;
StringBuffer sb = new StringBuffer();
try{
httpConnection = (HttpConnection) Connector.open(url);
conn.setRequestMethod( HttpConnection.GET );
conn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
int ch;
din = httpConnection.openDataInputStream();
int ch = din.read();
while ( ch != -1 ) {
sb.append( (char)ch );
ch = din.read();
}



}
catch (IOException ex) {
System.out.println(ex.toString());
}

catch (Exception ex) {
System.out.println(e.toString());
}
finally {
din.close();
httpConnection.close();
}

String sResult = sb.toString();
this.append(sResult);

}

OULD NADIF
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well It works better the mine
But dont forget you have to try & catch in the finally section.
Thanks!
 
Ould Nadif
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
yes you are right. I forget them.
OULD
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I asumed my error message depended on that I didnt close the httpConnection who has limited amount of connections.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
conn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");

Why? Please don't do that! The server will lose the telephone type information by doing that!!! The cellphone has its unique "User-Agent"!
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im using "System.getProperty("microedition.platform")" instead of "User-Agent".
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sebastian Green:
Im using "System.getProperty("microedition.platform")" instead of "User-Agent".



They don't always match, on certain cellphone "microedition.platform" even returns "j2me". I tried to use "microedition.platform", then given up. "User-Agent" is always reliable so far . But it also has a problem on certain cellphone, it only give server the value when you are downloading...

It is always a chanlledge no matter what...
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See: http://access1.sun.com/technotes/00555.html
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the server is controled by you, you can set a new header instead. I need the User-Agent to determine what phone is contacting my server, I will not alter the value of User-Agent, No matter who said what...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic