Dominik K Dominik K - 6 months ago 17
Android Question

Android Messaging app - Client - Server Communication

I want to write a private messaging app similar to Whats App. Smartphones with Android OS shall be the clients and communicating with one server. Now my question is how could that work out?

I guess the best way would be via a Restful webservice as port forwarding is absolutely no option. So what is the better way? - Client asking every few seconds if there are new messages or is there a way how the server can notify the client when there is a new message, and the client just sends a sign of life every few minutes? How does whats app do that?

Would UDP holepunching or reverse TCP any good in this case?

Answer

You're going to need real time communication. Basic approach would be using WebSockets. I would recommend you to use socket.io that already makes use of webSockets and is very scalable. Going for node.js is a great life saver in this matter. There are many socket.io java clientsto use in your android app such as:

https://github.com/Gottox/socket.io-java-client

https://github.com/nkzawa/socket.io-client.java

There are also things like Pusher that uses push messages and is ready for use.