3

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.

everydayapps
  • 455
  • 1
  • 5
  • 20

4 Answers4

0

Socket TCP connection:

  • (+) Reliable delivery due to TCP packet retransmission.
  • (-) Non-standard ports/protocals are blocked by many mobile internet providers
  • (-) Packet retransmission may cause delays and is thus not realtime.

Socket UDP connection

  • (+) If a packet comes through it is received with the lowest delay of those methods.
  • (-) Non-standard ports/protocals are blocked by many mobile internet providers
  • (-) Unreliable delivery, packets may be duplicated, truncated or dropped.

HttpUrlConnection:

  • (+) Many users can use your app (Many mobile internet providers block ports beside HTTP (80) and HTTPS (443) and use deep packet inspection (for HTTP) to make sure that the protocol is adhered to).
  • Most reliable due to TCP retransmission and proxies.
  • (-) TCP packet retransmission may cause delays and is thus not realtime.
  • (-) Proxies may add further delays causing it to be even less realtime.
HHK
  • 4,852
  • 1
  • 23
  • 40
0

if you have to transmit your data pretty often, it makes sense to use Sockets. You can keep your connection open for long time, sending your packets within the same channel and don't waste resources on re-openning it on each transfer.

injecteer
  • 20,038
  • 4
  • 45
  • 89
0

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.

everydayapps
  • 455
  • 1
  • 5
  • 20
0

If you are going to implement socket.io for a taxi app or large real time data transferring app, don't use socket.io.just use firebase or preferred http connection.

Ashana.Jackol
  • 3,064
  • 28
  • 22