• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

httpConnection limted?  RSS feed

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • 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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!