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
New Developer
roses_r
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

StreamConnection works on simulator but throws an exception on device

[ Edited ]

HI

 

I just tried debugging my app on a blackberry bold 9930 device. My app worked fine in the simulator but on the device it throws an IOException when im trying to make a tcp connection using StreamConnection. and I am using wifi on the device. I guess i need to check the netowrk availability or something? incase im using the mobile network or wifi?

 

anywasy this is how im doing it

 

try
{
    if(CoverageInfo.isCoverageSufficient(DELAY))
    {
        clientSocket = (StreamConnection)Connector.open("socket://" + MyAppServerIP + ":" + MyAppPort+";deviceside=true");
    }
}
catch (InterruptedIOException e)
{
    e.printStackTrace();
    System.out.println("Could not connect to server. " + e.getMessage());
    Dialog.alert("Could not connect to server");

    return;
}
catch (IOException e)
{
    e.printStackTrace();
    System.out.println("Could not connect to server. " + e.getMessage());
    Dialog.alert("Could not connect to server");

    return;
}

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: StreamConnection works on simulator but throws an exception on device

[ Edited ]

";deviceside=true"

is not WiFi, for that you need

";interface=wifi"

and no ";deviceside=true" (ignore what you read elsewhere if they say to code both):

 

You will find out more if you read this:

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

 

I recommend reviewing the networking tutorials and videos, type "network" in the search box to find them.

 

Edit: Link now fixed.  Sorry about that. 

New Developer
roses_r
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: StreamConnection works on simulator but throws an exception on device

[ Edited ]

I need either wifi or 3G to connect as in whatever data network possible. I guess i need to check for both in the app isnt it?

 

By the way your link leads me to a window to reply to  a message post or something.?

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: StreamConnection works on simulator but throws an exception on device

just use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/io/transport/ConnectionFactory...

as a sidenote: you cannot use Dialog.alert if you are not on the event thread.
and you should not execute blocking operations, like networking, on the event thread. use a separate thread.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
roses_r
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: StreamConnection works on simulator but throws an exception on device

HI have you got any example for using COnnectionFactory please? and yeah I should not use alert things

 

thank you

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: StreamConnection works on simulator but throws an exception on device

there is a httpdemo in your samples folder.
otherwise the docs of the class should be sufficient.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
roses_r
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: StreamConnection works on simulator but throws an exception on device

Hi simon i checked the samples and it doesnt use connectionFactory to create a connection.

New Developer
roses_r
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: StreamConnection works on simulator but throws an exception on device

In additiong simon whats reason for streamconnectin not to work on the device but on the simulator and whats difference between connectionFactory and StreamCOnnection?

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: StreamConnection works on simulator but throws an exception on device

watch this:
http://supportforums.blackberry.com/t5/Java-Development/Networking-Transports-II/ta-p/446742
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
roses_r
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch

Re: StreamConnection works on simulator but throws an exception on device

Hi I watched it but im having the same problem. it still throws an IOException. the code runs to a point where i assign a string url but then it would throw an exception. it runs perfectly fine on the balckberry simulator.