BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-08-2010, 01:30 AM   #1 (permalink)
New Member
 
Join Date: Feb 2010
Model: 9500
PIN: N/A
Carrier: Vodacom
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy SocketConnection sends but won't receive

Please Login to Remove!

Hi guys

I have a basic app which sends a number via a socket connection to a gateway, and should then read the response from the gateway. This application was written in J2ME and LWUIT, and works well on Symbian and similar handsets. I set out to port it for BlackBerry but I seem to have some basic networking troubles.

The J2ME code works 100% on the BlackBerry 9500 up until where it is supposed to receive. It just never gets any data in the inputstream (datainputstream to be more specific) and subsequently times out.

- Sending works 100% on the original code.
- I am testing all of this on the 9500 simulator with the MDS thing running before the emulator.
- I can also see that the gateway actually sends back a proper response
- I have tried to write a basic version of the application without using LWUIT, and using the BlackBerry JDE 4.7, as raw as possible, but nothing works. Still sending, but no receiving.

Code:
    public boolean Connect()
    {
        try
        {
            System.out.println("Attempting to connect to " + theServer + ":" + thePort);
            
            clientConnection = (SocketConnection)Connector.open("socket://" + theServer + ":" + thePort + ";deviceside=true");
                            
            //clientConnection.setSocketOption(SocketConnection.LINGER, 5);
            
            inputStream = clientConnection.openInputStream();
            outputStream = clientConnection.openOutputStream();
            
            connected = true;
            
            return true;
        }
        catch (InterruptedIOException ex)
        {
            System.out.println("Exception:" + ex.toString());
            ex.printStackTrace();
            System.out.println("Connection timeout/interupted!");
            connected = false;
            return false;
        }
        catch (IOException ex) 
        {
            System.out.println("Exception:" + ex.toString());
            ex.printStackTrace();
            System.out.println("Connection failure!");
            connected = false;
            return false;
        }
        catch (SecurityException ex)
        {
            System.out.println("Exception:" + ex.toString());
            ex.printStackTrace();
            System.out.println("Connection failure!");
            connected = false;
            return false;
        }
        catch (Exception ex)
        {
            System.out.println("Exception:" + ex.toString());
            ex.printStackTrace();
            System.out.println("Connection failure!");
            connected = false;
            return false;
        }
    }



        // and here is a sample of the receiving code


        // check for timeout, and if bytes are available, else continue
        while ((inputStream.available() <= 0) && (count <= timeoutsecs))
        {
            try
            {
                System.out.println("Zero bytes available bytes in inputStream: " + count);
                System.out.println("-----------------------------------------------");
                Thread.sleep(1000);
                count++;
            }
            catch (InterruptedException ex)
            {
                ex.printStackTrace();
                break;
            }
        }

        // reason for using dataInputStream in J2ME is
        // so I can make use of readInt(), readBoolean() etc

        header = 255;//inputStream.readShort();
        messageType = 7;//inputStream.readByte();
        messageStatus = true;//inputStream.readBoolean();

        //etc...
ANY clues as to why this thing / emulator is not receiving would be very helpful.

Thanks

w
Offline  
Old 02-10-2010, 04:47 AM   #2 (permalink)
New Member
 
Join Date: Feb 2010
Model: 9500
PIN: N/A
Carrier: Vodacom
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got this sorted by addind deviceside=true;apn=internet;etc... at the end of the connection parameters.

Only concern now is for users whose carrier does not use "internet" as the apn. In South Africa at least 1/4 of the carriers don't use it.

Any way of reading the APN details from the phone and use it as parameters in the connectionstring?
Offline  
Old 02-10-2010, 05:46 PM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

The user is able to configure APN settings via the Options pages.
__________________
My other Blackberry is a PlayBook.
Offline  




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