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
arunsingh
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified
Accepted Solution

Make HttpConnection work on device

Hi,

 

I have a java program that uses a HttpConnection (in the main thread). It works absolutely fine on the simulator but when I run it on my device (8310 Curve), it just do nothing ! Even after asking to allow the application make http connections.

I hear about some APN settings to be configured on device. I did that too ("airtelgprs.com" with username/password blank for Airtel, India).

 

Is there something else that is not letting my application establish http connections ? Can someone please tell me what all do I need to do tomake my http connections work on device ?

 

 

Thanks

- Arun

Please use plain text.
New Developer
davekakati
Posts: 7
Registered: ‎09-18-2008
My Device: Not Specified

Re: Make HttpConnection work on device

use - HttpConnection httpConn = (HttpConnection)Connector.open(url+";deviceside=true");
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Make HttpConnection work on device

I presume that you have reviewed:

 

What Is - Different ways to make an HTTP or socket connection
Article Number: DB-00396
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800451/800563/...

and this video:
http://www.blackberry.com/DevMediaLibrary/view.do?name=network

 

So you will understand that there are a variety of ways that the connection can be made on a real device, and these might be different to a simulator.

 

You say that you connect in the Main Thread.  Do you mean the Event Thread - i.e. the same Thread that is run as a result of screen interaction?  If so, this may work on the simulator, but will not work on the device for two reasons:

a) The device may attempt to seek authorization from your user via a 'Firewall' popup dialog - this can't be displayed while you won the Event Thread

b) The I/O is blocking, so will effectively prevent all User Interaction on the Device.

 

If this is not what you are doing, I would debug on the device and see where the problem is occurring and what Exception is being thrown.

 

I presume you are based in India and trying to use the India airtel service.  many people seem to have reported problems with this.  Search this forum for airtel and have a look.

 

Hope this helps.

 

 

Please use plain text.
Developer
arunsingh
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Make HttpConnection work on device

Hey thanks dave !

 

But it didnt work out either. I tried debugging it and got the following error :

"blocking operation not permitted on event dispatch thread". Has anyone any idea what it is all about ?

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Make HttpConnection work on device

That means that you cannot perform a blocking IO operation, like an HTTP connection, from the event handling thread in your program. You must create a worker thread to handle the HTTP connection activities.

 

 

Please use plain text.
Developer
arunsingh
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Make HttpConnection work on device

Thanks Peter & Rex !

 

Okay so I need to perform my http connections in a seperate thread. But I have an issue with the threads as well, I am not able to figure out how to stop / kill a thread ?

 

I am using JDE 4.2.1 and I can't see any method to kill a thread.

Please use plain text.
Administrator
MSohm
Posts: 14,362
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Make HttpConnection work on device

You can implement a stop method in your thread.  Please have a look at the httpdemo sample included with the BlackBerry JDE for an example.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
arunsingh
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Make HttpConnection work on device

Thanks Mark !

 

I now have a couple of more questions:

  1. Can I stop / cancel the process being carried out by the thread's run() method. If yes, how ? For example, if I am  downloading a file via http connection using a thread, can I cancel it? And start a new download later ?
  2. If I want to updat my Screen after a thread finishes its execution, how would it be done ?

I would really be greatful for any help on this.

 

 

 

Thanks

- Arun

Please use plain text.
Developer
Guest
Posts: 146
Registered: ‎11-05-2008
My Device: Not Specified

Re: Make HttpConnection work on device

1.I have tried to cancel during download by using interrupt method.The thread had stopped,but problem is that,it continues to download in the background until the end although all objects were null.

2.use repaint/rellayout method of UIApplication.But placed it in synchronized(uiApp.getAppEventlock()).where uiApp is object of UIApplication.Because the process is in separate thread and u have to require the event lock of current application.

Please use plain text.
Developer
arunsingh
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Make HttpConnection work on device

Thank you all, thank you so much ! I used a seperate thread and its working fine now :-)

 

 

- Arun

Please use plain text.