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


LP Weather Logic Seam And Flashing Tape (boxes) picture

LP Weather Logic Seam And Flashing Tape (boxes)

$200.00



York 031-02755-003 CARD FLASH YCAL EXT RANGE MMHP picture

York 031-02755-003 CARD FLASH YCAL EXT RANGE MMHP

$233.59



NEW Flash Lamp Assembly NEITZ CT-R Retroillumination Retinal Camera/ Slit Lamp picture

NEW Flash Lamp Assembly NEITZ CT-R Retroillumination Retinal Camera/ Slit Lamp

$244.94



Flash Technology 1118000 Red Led Light Fixture picture

Flash Technology 1118000 Red Led Light Fixture

$140.60



2711-NM11 PCMCIA Linear Flash Memory Card 256KB Fast Shipping AB 2711NM11 picture

2711-NM11 PCMCIA Linear Flash Memory Card 256KB Fast Shipping AB 2711NM11

$350.66



AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -  picture

AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -

$98.67







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