views:

1937

answers:

4

I'm writing an app for Blackberry that was originally implemented in standard J2ME. The network connection was done using Connector.open("socket://...:80/...") instead of http://

Now, I've implemented the connection using both methods, and it seems like some times, the socket method is more responsive, and some times it doesn't work at all. Is there a significant difference between the two? Mostly what I'm trying to achieve is responsiveness from the connection to get a smooth progress bar.

+1  A: 

Since both operate over a network I don't think you can guarantee a smooth progress bar. You might have more chance of that if you remind the person to stay in one place so you have a chance of a consistent connection ;)

There is less overhead with a socket connection than an HTTP one. In fact, HTTP connections run over the socket connection. You can take advantage of the reduced overhead of the socket connection to appear more responsive, but you will likely have more work to do than you would with HTTP. The API is more low-level so coding is more complex.

BrianLy
+1  A: 

Blackberry's implementation of http and https provide more options for connecting to the target server than socket, and, of course, implement all the HTTP protocol stuff for you. I've not benchmarked them, but it makes a certain amount of sense that direct TCP via socket would be quicker in some cases, especially if what is listening on port 80 isn't an HTTP server (no protocol overhead)

I've had difficulty in the past with different network providers, some requiring deviceside=true others deviceside=false, and no real way to know until the first support call for that network came in.

Mostly what I'm trying to achieve is responsiveness from the connection to get a smooth progress bar.

Pardon my saying so, but a "smooth progress bar" is "gilding the lily" - nice to have and look at, but not critical to the application's function, reliability or robustness. Go with what is more robust and reduces code size - likely http in this case.

Ken Gentle
I've not heard the phrase "gilding the lily" before, which I like. But mostly my problem is that the status bar waits for a very long time at the beginning, before the data is returned, and then progresses very quickly once the data is able to be read.
Ed Marty
Have you watched the BB Browser's progress bar? It starts moving as soon as you hit `GO` but is really waiting on the connection at that point. It increments in chunks (~10%?) until the halfway point, then starts updating at the same rate, but in incrementally smaller chunks.
Ken Gentle
Otherwise, you might try a `Connecting` modal dialog while the connection is being made and then use a progress bar _after_ the data starts. It will take some time for a connection to be established and a progress bar isn't going to move if it isn't updating somehow during that period.
Ken Gentle
More like gilding the butt-ugly-but-functional-thing.
Max Howell
+1  A: 

One difference between a socket and an HTTP connection on the BlackBerry is that HTTP connections may be transparently routed via an HTTP proxy in the case of BES and BIS connections.

Alexander
A: 

In theory sockets will be faster, but then you're responsible for managing the overhead of rolling your own protocol (depending on complexity). Though sockets are more lightweight, I've found that HTTP and all the comes with it greatly reduces the headache.

AtariPete