Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMPP, WebSocket, and other questions [closed]

My aim right now is just to make an Android app that has WhatsApp-like capabilities (not necessarily a clone of WhatsApp; just has similar, perhaps not-so-good features). What's important I guess is group chat, online/offline presence, as well as offline messaging.

Right now I'm aware mostly of the possibility of having a WebSocket server (because I was introduced to it as a real-time solution that could open me up to endless possibilities), and I've tested it before--it looks good. However, I'm facing the following issues:

  1. I don't know how to manage online/offline presences; do I have to implement that myself? Perhaps the Android client querying the server every 30s if his friends are still connected...
  2. How about offline messaging? If a particular person is not connected, the message will not be delivered to him. Does the message then need to be stored somewhere (say MSSQL), and then when the person logs in the client will automatically retrieve all offline messages from the server?
  3. What about group chats? I'm unsure how WebSocket is able to acheive that, do I have to implement that separately as well? That would mean a lot of biz logic to work on (and a whole lot of room for bugs to appear)...

I'm aware there is a protocol called XMPP (and that it's totally different from WebSocket) but I'm not sure how it relates to my problem. Is XMPP my silver bullet (i.e. are there .NET libraries out there that implement most of it there for me?). I've also heard of Comet, but I don't know how it relates at all...

There are so many missing pieces, I thought implementing my chat server/client would be a piece of cake, but apparently not so. Anyone with a l'il experience can give me some feedback?

like image 413
matt Avatar asked Nov 13 '13 09:11

matt


2 Answers

You can and should be using WebSocket for presence and instant messaging functionality. In fact, instant messaging is the "Hello world" example of the WebSocket world.

Also, the WebSocket standard was designed to support higher level, richer business protocols (which ironically the standard calls sub-protocols). XMPP is one of such protocols, and there are several implementations out there with the exact features you're looking for.

If you'd like to try it out, Kaazing (the company I work for) has a free download available. It contains an open source XMPP server (OpenFire), along with the XMPP edition of a pre-configured Kaazing WebSocket Gateway. What Kaazing does is it extends the XMPP protocol to Web clients over WebSocket. It does so transparently, so from the XMPP server's perspective your (browser) client is just another XMPP client.

Another good resource is chapter 4 of The Definitive Guide to HTML5 WebSocket (of which I'm a co-author), titled Building Instant Messaging and Chat over WebSocket with XMPP. The book also comes with a free downloadable VM with open source software pre-installed and configured for your testing. Here you can see detailed screencasts of the VM - to get an idea.

Hope this helps.

like image 163
Peter Moskovits Avatar answered Oct 15 '22 23:10

Peter Moskovits


let's go per parts:

first: Do not use sockets. That means you will need to keep a service running and maintain a connection at all times on each client device. That will drain the battery like crazy and no one will use it. What every-single-one of those apps use including WhatsApp, Hangout, Gmail, Facebook messenger is the Google cloud messaging (GCM) http://developer.android.com/google/gcm/index.html service.

  1. maybe you want can send those status change via GCM at the moment they happen, or once the user enters the friend-list screen you do a one-off query with the status, the important thing here is that you will not query every 30 seconds in a mobile device.

  2. Yes, if the device is not connected your server have to do the stuff. And I don't believe you'll use SQL, what a lot of companies are doing nowadays is noSQL approaches due to scalability, but it's not my expertise.

  3. I'm not sure what you're asking here. You're mixing how you're going to send the data with how your application will treat the data. Those are two completely separate things, learn the difference. Example, Someone could create a group chat that works over WiFi-Direct over UDP (that's HOW the data will be sent) but what u do with this data doesn't matter, it could have arrived over Bluetooth that will be the same for the parser/interpreter. It's just data.

Good luck.

like image 43
Budius Avatar answered Oct 16 '22 00:10

Budius