8

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.

Bart
  • 19,692
  • 7
  • 68
  • 77
user638049
  • 189
  • 2
  • 10

1 Answers1

8

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?

Community
  • 1
  • 1
kabuko
  • 36,028
  • 10
  • 80
  • 93
  • ok so does XMPP talk to a windows server/.net webservice? How do you get it to talk to your own webservices. Also, does it recieve messages without having to poll the server every so often? I am not familiar with XMPP and have google it but not really gotten a good definition. – user638049 Feb 13 '12 at 18:51
  • This will not be for gtalk. It will be a third party chat program that I am creating. I will be hosting my own webservices and storing my all of the chat messages myself. – user638049 Feb 13 '12 at 19:02
  • Ok, so after reading your new comments and looking into it some more, I believe I understand. I basically can create the xmpp webservices by using of the server components, and then just use the protocol on my mobile device to connect to it. Is it that simple, meaning the protocol takes care of the pushing for me? – user638049 Feb 13 '12 at 19:46
  • What do you think about farebase? – Sirop4ik Aug 25 '16 at 13:42