0

There is lots of documentation about how to implement an http or https connection in android, through Apache HTTP Client, or HttpsUrlConnection, but I was wondering if there are other protocols / communication paradigms which I could consider in order to communicate with a server. Indeed, from my experience and readings, HttpsUrlConnection is pretty easy to setup and provides a good level of security. But I also wish to consider other factors such as performance and reliability.

Are there other protocols out there for Android which could be interesting for me?

Loïs Talagrand
  • 810
  • 2
  • 13
  • 32

3 Answers3

0

Maybe you are looking for UDP?

http://developer.android.com/reference/java/net/DatagramSocket.html

Erwin Moller
  • 2,375
  • 14
  • 22
  • Is the performance increase that great though? Because from what I understand, UDP is less secure and less reliable – Loïs Talagrand Apr 13 '16 at 15:17
  • It is UNRELIABLE. But very fast. Ideal for gaming because it reduces lag. But you must be prepared to code in such a way, you are able to miss an occasional packet. – Erwin Moller Apr 13 '16 at 15:19
  • I don't think UDP is the best choice here - he specifically mentions `performance and reliability`. Better is to use a seasoned HTTP Library. Such as OkHttp. – Knossos Apr 13 '16 at 15:20
  • True. But I get the impression the OP is making up his mind. And UDP is the first thing that comes to mind when he needs more speed. http://stackoverflow.com/questions/1099672/when-is-it-appropriate-to-use-udp-instead-of-tcp contains a nice discussion. I would advise the OP to read that, and then decide if UDP will be appropriate. – Erwin Moller Apr 13 '16 at 15:23
0

Apache HTTP Client, or HttpsUrlConnection both are reliable. Performance wise HttpURLConnection is much faster than HttpClient.

Visit http://openjavafaq.blogspot.in/2009/03/httpclient-vs-httpurlconnection.html

Based on following test parameters- Test parameters: 15 threads 10 Loop Counts Average time take by Connection to complete 150 requests: 7.61 milliseconds Average time take by HttpClient to complete 150 requests: 85.89 milliseconds Even thought the performance of HttpURLConnection is much faster , it does not give good control over managing the Http connections, it is always feasible to use HttpClient in production environment, when high volume of transactions are expected.

For comparison refer to: http://www.innovation.ch/java/HTTPClient/urlcon_vs_httpclient.html

USKMobility
  • 5,721
  • 2
  • 27
  • 34
0

there 2 things you mention http client and communication protocol.

Well to design a system you have to consider

1) The communication protocol(s)

and then

2) The client/server software

going for http protocol you have clients(okhttp being one of them) and servers which supports various versions/variants of it suck as the most widely used http 1.1 the 'new' http 2.0, spdy, http streaming etc. If you plan to do messaging/event driven app you may want to try mqtt or WebSockets. These all can come with some sort of security protocols on top(actually under) of it which may introduce some performance drops. These all also work on top of TCP.

Somebody wrongly compared UDP to HTTP where it is more appropriate to compare TCP_vs_UDP. We have mentioned some drawbacks of UDP however QUIC can handle those.

So there are many options and depends on what you want to do and what you can do.

Coming back to the way you choose seems that to decide about 1) can be difficult. So what you can do is to decide as good as possible about the protocol(s) you want to use but also choose a 'smart' client which can handle those in case you change your mind, like okhttp or netty. You can also choose something like a modular solution which can plug and play different implementations while your code that makes the calls stays the same(netty can do this also to some extent), like volley or jus (based on volley idea). In that case you stay flexible.

Update: there is also nice info about various protocols in this question

Community
  • 1
  • 1
kalin
  • 3,546
  • 2
  • 25
  • 31