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

httpConnection limted?

 
Sebastian Green
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

 
Ould Nadif
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.
 
Roseanne Zhang
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...
 
Johann Evans
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic