BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-09-2006, 10:43 AM   #1
rr99bb
New Member
 
Join Date: Oct 2005
Model: 7290
Posts: 5
Default Max Connections opened on HttpConnection

Please Login to Remove!

I have a thread which makes HTTP requests and the code ensures that at most 2 simultaneous connections are made at any one time. However, I get IOExceptions which say "Max connections opened".

I am closing connections cleanly. Does anyone have any ideas on this?

I am using midp1.1 and the 7290.

Thanks.
Offline  
Old 01-09-2006, 04:39 PM   #2
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

When does it happen?

Try to open and close the connection 11 times. If you get the max connection happening on the 11 try, then you are probably not closing them correctly.

20 is the max amount of HTTP connection allowed.

Last edited by eradis; 01-09-2006 at 04:46 PM..
Offline  
Old 01-09-2006, 05:52 PM   #3
rr99bb
New Member
 
Join Date: Oct 2005
Model: 7290
Posts: 5
Default

Its quite random how it happens.

I am pretty sure i close the connection properly. I first close the input stream and then the connection. Is this the correct way?
Offline  
Old 01-09-2006, 06:48 PM   #4
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

It should look something like this:

Code:
import java.io.*;
import javax.microedition.io.*;

String url = "http://www.google.com";
HttpConnection conn = null;
InputStream in = null;

try {
    conn = (HttpConnection) Connector.open( url );
    int rc = conn.getResponseCode();
    if( rc == HttpConnection.HTTP_OK ){
        in = conn.openInputStream();
    }
}
catch( IOException e ){
    System.out.println( "IOException: " + e.toString() );
}
catch( Exception e ){
    System.out.println( "Exception: " + e.toString() );
}
finally {
    if( in != null ){
        try { in.close(); } catch( IOException e ){System.out.println( "IOException: " + e.toString() );}
    }
    if( conn != null ){
        try { conn.close(); } catch( IOException e ){System.out.println( "IOException: " + e.toString() );}
    }
}
I assume the HTTP connection happens in a separate thread so it could easily be missed.

Try using the JDE debugger to view more info.
Offline  
Old 01-10-2006, 06:49 AM   #5
rr99bb
New Member
 
Join Date: Oct 2005
Model: 7290
Posts: 5
Default

Yep, that's what i have.

My application polls (lets call it fetch) a servlet in a thread. So it does a fetch and sleeps for 1000ms and then fetches until the app terminates. While this is going on the user can make a new send request. But i always ensure that i only have 2 simultaneous connections at most. Yet i still get max connections.

Does that sound bad?

What kind of things should i be looking out for in the debugger?

(thanks for your help)
Offline  
Old 01-10-2006, 05:26 PM   #6
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

Use the JDE to look at all the threads. I'm sure there is an error in there somewhere (in the threading connection).

Is this happening in the simulator? If yes then for sure there is a logic error. If only on the device, make sure you are running the latest device code.
Offline  
Old 01-10-2006, 05:28 PM   #7
rr99bb
New Member
 
Join Date: Oct 2005
Model: 7290
Posts: 5
Default

Will try that, it only happens for the device. I have the latest os from vodafone.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


GE (Datex Ohmeda) Flow Sensor Transducer for Aestiva 5, Aespire, Avance, Aisys  picture

GE (Datex Ohmeda) Flow Sensor Transducer for Aestiva 5, Aespire, Avance, Aisys

$309.95



Mindray P7-3s Phased Array Ultrasound Transducer for M7 & M9 Ultrasound Machines picture

Mindray P7-3s Phased Array Ultrasound Transducer for M7 & M9 Ultrasound Machines

$4500.00



Fukuda Pressure Transducer VR-55PT/TCD picture

Fukuda Pressure Transducer VR-55PT/TCD

$787.46



Novotechnik Position Transducer Type TLH 360 picture

Novotechnik Position Transducer Type TLH 360

$180.00



US Stock 110VAC 60W 40KHz Ultrasonic Cleaning Transducer Cleaner & Driver Board picture

US Stock 110VAC 60W 40KHz Ultrasonic Cleaning Transducer Cleaner & Driver Board

$50.53



60W 40KHz Silvery Ultrasonic Piezoelectric Transducer High Conversion Efficiency picture

60W 40KHz Silvery Ultrasonic Piezoelectric Transducer High Conversion Efficiency

$18.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.