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


1pcs used TSXMFPP128K Memory Card picture

1pcs used TSXMFPP128K Memory Card

$175.00



Argolladora We R Memory Keepers Heidi Swapp Cinch Binding Machine 71050-9 by AC picture

Argolladora We R Memory Keepers Heidi Swapp Cinch Binding Machine 71050-9 by AC

$79.99



Desktop Memory Case Tray Case for PC DDR DRAM RAM DIMM Modules - 2 fits 100 New picture

Desktop Memory Case Tray Case for PC DDR DRAM RAM DIMM Modules - 2 fits 100 New

$20.50



Memory Blister Pack Box for DDR DIMM Module Anti Static - Lot of 6 18 35 100 200 picture

Memory Blister Pack Box for DDR DIMM Module Anti Static - Lot of 6 18 35 100 200

$17.95



NEW Mitsubishi A1SNMCA-8KE Memory Cassette picture

NEW Mitsubishi A1SNMCA-8KE Memory Cassette

$151.62



Abb MEM86-E128K Back Up Memory Board picture

Abb MEM86-E128K Back Up Memory Board

$268.38







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