BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-22-2008, 02:22 PM   #1
knight9
New Member
 
Join Date: Sep 2008
Model: 8310
PIN: N/A
Carrier: ATT
Posts: 3
Default BAD DNS and Port is already bound: 19780

Please Login to Remove!

I have been struggling the past few days to track down why I consistently get these exceptions within my application when attempting to use HTTPConnection. I have scoured numerous forums and no one seem to be having the same problem as me. I would appreciate any insight anyone might have.

I am using a makeConnection function based on the Browser sample code, but it seems to be very unreliable. The code funtions 100% on the simulator but on the device itself I can only get some of the connections to connect and return data. I make two types of requests, a few POST requests to our server and then some GET requests to retrieve image data from amazon s3 servers. It seems like the first few initail requests to our server work fairly reliably, then exceptions start occuring.

The requests to amazon fail consistently with "net.rim.device.cldc.io.dns.DNSException: Bad DNS Address". However, I am certain that the address being requested is valid, because the image loads perfectly in the blackberry browser when the URL is entered.

The request to our server seems to fail when multiple connections are attempted or connections are attempted too frequently and usually fail with "net.rim.device.cldc.io.dns.DNSException: Port is already bound: 19780" but have recieved other exceptions as well such as "java.io.IOException: Open tunnel - max timeout" and "java.io.IOException: Unable to open connection."

The application runs in a multi-threaded environment where each HTTPConnection request is handled by one of 5 worker threads, which means we could have up to 5 active connections at any given time. Below you will find the code used to create the connection(almost exactly out of the JDE browser sample code with the addtion of getBES() to set connection string), the Exceptions are thrown on the Connector.open(url) call

Details:
Device: 8310 on ATT running V4.2.2.170 (Platform 2.5.0.30) without MDS just Blackberry Internet Service. There is no firewall enabled, the appliation has been granted all permissions, The device has EDGE coverage with 4 bars of signal and the Blackberry Browser is able to hit all of the links my application can not.

I am using JDE 4.2.1 to build and sign the code.

Now for code snippet:

Code:
public static HttpConnection makeConnection(String inUrl, HttpHeaders requestHeaders, byte[] postData) {
        String url = inUrl + getBES(); //NOTE this is using deviceside=true
        HttpConnection conn = null;
        try {
            if (requestHeaders != null) {

                //
                // Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP
                // request if the referring page was transferred with a secure protocol.
                String referer = requestHeaders.getPropertyValue("referer");
                boolean sendReferrer = true;

                if (referer != null && StringUtilities.startsWithIgnoreCase(referer, "https:") && !StringUtilities.startsWithIgnoreCase(url, "https:")) {
                    sendReferrer = false;
                }

                int size = requestHeaders.size();
                for (int i = 0; i < size;) {
                    String header = requestHeaders.getPropertyKey(i);

                    // Remove referer header if needed.
                    if (!sendReferrer && header.equals("referer")) {
                        requestHeaders.removeProperty(i);
                        --size;
                        continue;
                    }

                    String value = requestHeaders.getPropertyValue(i++);
                    if (value != null) {
                        conn.setRequestProperty(header, value);
                    }
                }
            }
            //make sure a user-agent is set, harcode the user agent the blackberry browser on simulator uses.
            if(conn != null)
                conn.setRequestProperty("User-Agent", "BlackBerry8300/4.5.0.44 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/-1");
           
            if (postData == null) {
                conn.setRequestMethod(HttpConnection.GET);
            } else {
                conn.setRequestMethod(HttpConnection.POST);

                conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, String.valueOf(postData.length));

                out = conn.openOutputStream();
                out.write(postData);

            }
      
        }
        catch (Exception e1){
            System.out.println(Thread.currentThread().getName() + " - Utilities:makeConnection Exception(" + conn + "): " + e1.toString());;
        }
        finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e2) {
                }
            }
        }
        return conn;
    }

    private static String getBES() {
        ServiceRecord[] ippprecordArray = ServiceBook.getSB().findRecordsByCid("IPPP");
        if (ippprecordArray == null) {
            return null;
        }

        int numRecords = ippprecordArray.length;
        for (int i = 0; i < numRecords; i++) {
            ServiceRecord ipppRecord = ippprecordArray[i];

            if (ipppRecord.isValid()) {
                int encryptionMode = ipppRecord.getEncryptionMode();
                if (encryptionMode == ServiceRecord.ENCRYPT_RIM) {
                    return ";deviceside=false";
                }
            }
        }
        //use apn instead
        return ";deviceside=true";
    }
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


Commodore Amiga 2000 GVP A2000-030 Combo  (40Mhz) 8mb Ram Rev.3 W/ Caddy & Cable picture

Commodore Amiga 2000 GVP A2000-030 Combo (40Mhz) 8mb Ram Rev.3 W/ Caddy & Cable

$699.00



GVP G-Force 040 Combo Rev 6 Accelerator Card for Amiga A2000 33MHz 68040 w/ 8MB picture

GVP G-Force 040 Combo Rev 6 Accelerator Card for Amiga A2000 33MHz 68040 w/ 8MB

$825.00



Motorola 68060 68EC060 MC68EC060RC75 CPU / Processor AMIGA unused, new USA stock picture

Motorola 68060 68EC060 MC68EC060RC75 CPU / Processor AMIGA unused, new USA stock

$69.99



6500/1 A 6502 VARIENT CPU COMMODORE USE IN AMIGA KB & 1520 PLOTTER NMOS NCR NOS picture

6500/1 A 6502 VARIENT CPU COMMODORE USE IN AMIGA KB & 1520 PLOTTER NMOS NCR NOS

$5.89



Motorola MC68020RC16E 68020 1C10H Motorola Vintage CPU AMIGA GOLD picture

Motorola MC68020RC16E 68020 1C10H Motorola Vintage CPU AMIGA GOLD

$16.99



1pcs Used Mitsubishi A500 inverter FR-A540-1.5K 1.5KW 380V picture

1pcs Used Mitsubishi A500 inverter FR-A540-1.5K 1.5KW 380V

$203.80







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