androidsocketshttpurlconnectionsocketchannel

Use HTTP or Socket from Android


I have to send data from Android phone to a server very frequently say every 100ms.(battery is not an issue). I am debating with myself whether it is OK to use the standard Java URL connection for this purpose or to create my own custom socket implementation using SocketChannel. I have full control over both endpoints and free to choose anything I want. What are pros and cons of each of these methods? Any other approach? Note that I already tried Google XMPP. But found that many data points were getting dropped. Received no reply from Google about it.

Note that reliability is a primary concern. I must get every sample in real time unless of course there is some problem in radio link itself. Please provide some pointers.


Solution

  • I considered various options: http, xmpp, custom socket implementation .. finally I stumbled upon https://github.com/Gottox/socket.io-java-client. Worked painlessly. I was up and running in no time! Of course it helped that I had used socket.io in an earlier project. I never imagined there would be a java client for socket.io! Guess I was not asking the right questions. So far this solution is working very well. I will test and post updates if any. DO consider this option if you need to implement persistent real time communication.