Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
neeraj_chauhan
Posts: 86
Registered: ‎10-28-2010
My Device: Blackberry Curve, Bold and Strom
Accepted Solution

Socket connection is not working with SIM Network

Hi all,

 

                I have created a socket connection. It is working fine when I am using WiFi and iam able to successfully upload the data and get correct response.   But when I am using GPRS/SIM Network I am getting "Unauthorized response" as response. I already check with default browser of blackberry, here internet is working fine.

 

              Can anyone tell me why socket connection is not working when I am using SIM Network.

 

              If anyone know about internal Setting or following setting of blackberry than also tell me

              " Option -> Advanced Option -> TCP"

 

Thanks

Neeraj Chauhan

Thanks & Regards
Neeraj Chauhan
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Socket connection is not working with SIM Network

Have you reviewed this - which connection method you are trying to use?

 

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

Please use plain text.
Developer
neeraj_chauhan
Posts: 86
Registered: ‎10-28-2010
My Device: Blackberry Curve, Bold and Strom

Re: Socket connection is not working with SIM Network

Hi Peter,

 

            I am using the same format as given by Blackberry.

 

For WiFi :- It's working fine

 

StreamConnection connection = (StreamConnection)Connector.open("socket://testserver:600;interface=wifi");

 

I am writing  my code below for SIM Network And response from server

 

For Sim : it's not working

 

StreamConnection connection = (StreamConnection)Connector.open("socket://testserver:600;deviceside=true");

 _in = new DataInputStream(connection.openDataInputStream());
            _out = new DataOutputStream(connection.openDataOutputStream());
            String strResponse = exchange("##$Test");
           

 

private String exchange(String data)
    {
        try
        {
            int length = data.getBytes().length;
            _out.write(data.getBytes(),0,length);
            
            char[] input = new char[length];
            String str ="";
            
            for (int i = 0; i < length && i<10; ++i)
            {
                input[i] = (char)_in.read();
                str = str + input[i];
                System.out.println("Char"+input[i]);
            }
            System.out.println("String value"+str);

            return str;
        }
        catch (Exception e)
        {
            return "";
        }
        
    }

in case of  SIM strResponse = "Unauthorized Response";

 

 

Thanks & Regards
Neeraj Chauhan
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Socket connection is not working with SIM Network

[ Edited ]

I think you need to do some background reading to understand the various connection methods that you might want to use.

 

Please have a read of this thread, especially reviewing the required reading (which includes the KB article I referenced above)

 

http://supportforums.blackberry.com/t5/Java-Development/Connecting-your-BlackBerry-http-and-socket-c...

Please use plain text.
Developer
neeraj_chauhan
Posts: 86
Registered: ‎10-28-2010
My Device: Blackberry Curve, Bold and Strom

Re: Socket connection is not working with SIM Network

Thanks Peter,

 

        For Your support.............Now my application is working fine in both cases (SIM network as well as Wi-Fi). So, I am closing my ticket.

 

Thanks & Regards

Neeraj Chauhan

 

Thanks & Regards
Neeraj Chauhan
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Socket connection is not working with SIM Network

Glad you have it sorted.  Can you quickly summarize how you did it for the next person who has a similar problem and finds this Thread?

Please use plain text.
Developer
neeraj_chauhan
Posts: 86
Registered: ‎10-28-2010
My Device: Blackberry Curve, Bold and Strom

Re: Socket connection is not working with SIM Network

Hi Peter,

 

             Actully i made a function for connection string. This class check available connection then return the connection String for example in case of SIM it reurn ";deviceside=false".

 

In this function i am checking one by one for all connection

1. Wi-Fi

2. WAp

.

.

.5. Sim Network

 

So when I am using Sim it start checking for connection string return the Connection string for WAP

 

I just reorder my class and now I am checking 1. Wi-Fi and 2. SIM and so on. So now it return the connection string for SIM...

 

 

 

Thanks

Neeraj Chauhan

Thanks & Regards
Neeraj Chauhan
Please use plain text.