java 在 Android 和 iOS 中使用的最佳服务器客户端通信协议是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4278949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:39:31  来源:igfitidea点击:

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

javaandroidiosprotocols

提问by André

We have a server application (implemented in Java) that will provide some data for our mobile apps. The apps will be created for Android and iOS.

我们有一个服务器应用程序(用 Java 实现),它将为我们的移动应用程序提供一些数据。这些应用程序将针对 Android 和 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.

编辑:它应该是一个请求-> 响应 szenario。数据丢失是不可接受的。答案可能包含一长串数据,因此需要较少的开销。

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.

客户端应请求数据(指定的键和一些定义的参数),例如“给我文件夹 x 中具有扩展名 y 的所有文件”。服务器用列表回答。

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

第一个想法是使用 XMLRPC,但生成的响应太大。

回答by Felix

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.

对于大多数应用程序,HTTP(S) 是最好的协议。开销(即标头)非常小,传输可以被压缩,连接可以被保护(通过 SSL)。此外,端口 80 (HTTP) 和 443 (HTTPS) 将在 99% 的情况下打开。其他端口不是 - 例如,除非您支付额外费用,否则某些运营商会阻止所有其他端口。



As for the implementation, I suggest a RESTful web serviceusing the JSONformat. 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 downloadedas standalone for other applications as well). Check out this question, too:

至于实现,我建议使用JSON格式的RESTful Web 服务。JSON 标准化良好,开销小,并且您拥有可以使用任何语言使用它的良好库(请查看,它与 Android 捆绑在一起,但也可以作为其他应用程序的独立下载)。也看看这个问题:org.json

回答by XEENA

Use Hymanson parser or Gson parser instead of JSON Parser.

使用 Hymanson 解析器或 Gson 解析器代替 JSON 解析器。

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

1.Hyman逊是2X比JSON更快,很适合用于分析复杂和非常大jsons。

2.Gsoncompetitively faster than JSON.

2. Gson比 JSON 快得多。

回答by Murtaza Kanchwala

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

在 My Opinion 中,您应该使用基于面向文档结构的 REST/SOAP Web 服务,这将有助于大型响应。

You can also integerate Apache SOLRfor 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.

您还可以为此目的对Apache SOLR进行整数化,这用于索引大型数据集,速度更快,并且还启用了 REST,您可以在 SOLR 核心中索引您的数据,然后从客户端(即 IOS、Android)创建 REST 调用, PHP 等,所以文档已经被处理了,你只需要根据客户端的需要添加过滤器和其他东西。

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

如果您在这方面需要更多帮助,请告诉我。