Android - Sockets vs Polling
Asked Answered
H

3

6

As part of an Android app I'm developing there is a chat room feature. We have a server which can process the incoming messages and store the messages. Is it better to keep a socket connection open between the phone and the server so the server can send any new messages to the phone, or is it better for the phone to poll the server for new chat messages?

Holly answered 15/9, 2011 at 15:52 Comment(0)
M
4

It is bad solution with poll for app that have randomly posting data. What I want to say is that polling data is useful when you have something that is happening discrete like every 5 minutes or something like that. this is not the case with chat, some user can post something ones in a hour , some can post 30 times in 2 minutes

so keep your sockets open

Marque answered 15/9, 2011 at 16:3 Comment(0)
L
1

Polling lacks real-time connection and a persistant connection is battery draining. I think that what you are looking for is a combination of "push"-ing and persistant connection. You would wake your phone via push, and then establish a connection via sockets to handle chat.

I suggest reading this article. I'm not sure if it mentions c2dm, the google push service.

Lorin answered 15/9, 2011 at 16:2 Comment(2)
Can you qualify your statement "Persistent connection is battery draining"?Overview
"Persistent connection is battery draining" because keeping a connection open means you will need a constant resource usage.Thermosphere
N
0

I would keep the socket open if you are worried about instant messaging, it takes time to setup the socket connection especially if you are using the GSM connection. I have seen it take 10 secs or more to open up a socket on 3G, much less if on WiFi.

Neva answered 15/9, 2011 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.