tags:

views:

344

answers:

2

Hi there,

First off, let me say that feel free to recommend me if long lived TCP persistent connections are the way to go or persistent HTTP connections are better.

I've also pre-read that instead of having a persistent connection, I can have a polling mechanism.

I'm just asking in the curious interest of how can I create a persistent connection from Android to a server?

Thanks!

+2  A: 

Long lived TCP connections are a bad idea in anything mobile because the network is so spotty. Personally I use UDP or transient HTTP connections with an HTTP session concept.

sylvanaar
What's a transient HTTP connection? And by HTTP session concept, you mean just the simple session storing where we store the token and pass it back and forth between client and server?
Tereno
A: 

This really depends on what your requirements are and if you actually need a persistant connection or not.

If you have time-sensitive data you need to push from the server to the device as soon as it becomes available, then a persistant TCP connection is your best bet.

If it is acceptable that your server and device only periodically exchange information, then polling or HTTP requests may be a better choice.

Personally I think a well-implemented long-lived TCP connection with a binary protocol is the superior choice when dealing with persistant connections where information must always be current.

HTTP connections are generally expensive in terms of overhead for each packet, especially if you are using an XML-based protocol, such as SOAP. Also, connecting and tearing down sockets all the time is generally quite expensive.

On the other hand, persistant TCP connections can be tricky to implement on both the client and server side. Battery life is a huge factor on the device side, and if you are expecting anything more than a handful of users connected at once then you may have to implement an asynchronous communication model on the server side, which brings its own set of challenges.

Good luck!

jscharf