开发者

What is the best server client communication protocol to use in Android and iOS?

We have a server application (implemented in Java) that will provide some data 开发者_如何学Gofor our mobile apps. The apps will be created for Android and iOS.

Which is the best protocol / library for this purpose? The overhead of the protocol should be as small as possible.

Thanks.

Edit: It should be a request->response szenario. Data lost is not acceptable. The answer could contain a long list of data and therfore less overhead is required.

The client shall request the data (a specified key and some definied parameters) e.g. "give me all file from folder x that have the extension y". The server answers with the list.

The first idea was using XMLRPC, but the generated responses are too large.


For most applications, HTTP(S) is the best protocol to use. The overhead (i.e. headers) is pretty small, the transfer can be gzipped, the connection can be secured (via SSL). Also, ports 80 (HTTP) and 443 (HTTPS) will be open in 99% of cases. Other ports are not -- for example some carriers block all other ports unless you pay extra.


As for the implementation, I suggest a RESTful web service using the JSON format. JSON is well standardized, has small overhead and you have good libraries for working with it in any language (check out org.json, which is bundled with Android but can be downloaded as standalone for other applications as well). Check out this question, too:

  • https://stackoverflow.com/questions/338586/a-better-java-json-library


Use Jackson parser or Gson parser instead of JSON Parser.

1.Jackson is 2X faster than JSON and it is suitable for parsing complex and extremely big jsons.

2.Gson competitively faster than JSON.


In My Opinion, you should use REST/SOAP web sevices based on document-oriented structures, This will be helpful in the Large response.

You can also integerate Apache SOLR for this Purpose this is used for Indexing the Large Datasets and is even much faster and it is also REST enabled, you can index your data in the SOLR cores and then create REST calls from Client i.e. IOS, Android, PHP etc. so the documents will already be processed and you just need to add filters and other things as required on client.

Let me know if you want any more help regarding this.


Another protocol you can use today (2021) is gRPC. It has many advantages over classic REST APIs for mobile apps, namely faster serialization and smaller data load (because it's binary, not JSON).

Because of that it's also easier for device bateries.

Transmitting data from mobile devices to a backend server can be a very resource-intensive process. Using the standard HTTP/1.1 protocol, frequent connections from a mobile device to a cloud service can drain the battery, increase latency, and block other apps from connecting. By default, gRPC runs on top of HTTP/2, which introduces bi-directional streaming, flow control, header compression, and the ability to multiplex requests over a single TCP/IP connection. The result is that gRPC can reduce resource usage, resulting in lower response times between your app and services running in the cloud, reduced network usage, and longer battery life for client running on mobile devices.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜