Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best practices on creating a chat app in android [closed]

Tags:

android

chat

I am going to create an android chat app. Actually chat is going to be a feature of the app. I want to know what are the best practices regarding chat apps with android. The two options that I am familiar with are C2MD and just a custom polling of the server db every few seconds.

Now, I know that C2MD is supposed to be great and all, but from my understanding it is not that reliable. I have tried to implement it and it does not seem to be working. Also, if for some reason something happens on googles end(like their servers are down - not likely but could happen) I have no way to contact them, and am at their time frame.

Now if I do my own thing (a basic approach where I send the message that the user creates, and then periodically check the server to see if any new messages have arrived) seems ok except, in order to have a decent user experience, my polling of my server would have to be like ever 5 seconds or so, and that is going to chew up battery like crazy. This is really my main drawback from using this approach.

So, I am wondering there is a better way out there that I am not aware of. Please any help, architecture structures, anything would be helpful.

like image 829
user638049 Avatar asked Feb 13 '12 18:02

user638049


1 Answers

You should look at using XMPP. You can search StackOverflow for Android XMPP and you'll probably end up here which recommends using some variant of Smack (an XMPP client library).

Update to address comments:

First off, XMPP is a protocol, not a client or server. One of the benefits of using it is that there are XMPP client and server implementations widely available. The Wikipedia article addresses most of your questions.

Regarding your comment on gtalk:

The architecture of the XMPP network is similar to email; anyone can run their own XMPP server and there is no central master server.

Regarding polling:

XMPP could use HTTP in two ways: polling[21] and binding.[22] The polling method, now deprecated, essentially implies messages stored on a server-side database are being fetched (and posted) regularly by an XMPP client by way of HTTP 'GET' and 'POST' requests. With HTTP binding, the client uses longer-lived HTTP connections to receive messages as soon as they are sent. This push model of notification is more efficient than polling, where many of the polls return no new data.

It can also use WebSockets.

Regarding .NET integration (if you need it... if you don't, you could just run your own XMPP server), you can just search StackOverflow for XMPP and .NET and you can get some questions/ideas around .NET server integration with XMPP servers like with this question: Opensource .Net Jabber/XMPP server?

like image 162
kabuko Avatar answered Sep 20 '22 16:09

kabuko