java Android 中客户端服务器通信的选项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1690229/
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-29 17:36:59  来源:igfitidea点击:

Options for Client Server Communication in Android

javaandroidnetworkingclient-servermiddleware

提问by chrisbunney

I'm currently in the research phase of my dissertation project.

我目前处于我的论文项目的研究阶段。

My project is a ticket booking system for a mobile device and I have chosen to target Android.

我的项目是一个用于移动设备的票务预订系统,我选择面向 Android。

I anticipate the need for a client/server architecture with a central server, and so am currently looking at how Android could communicate with such a server. The server would grant the client access to ticketing information, and the client would send information about ticket bookings to the server. I'm looking at Java EE for the server as Java is the language I'm most experienced with.

我预计需要一个带有中央服务器的客户端/服务器架构,因此我目前正在研究 Android 如何与这样的服务器进行通信。服务器将授予客户端访问票务信息的权限,客户端将有关票务预订的信息发送到服务器。我正在研究用于服务器的 Java EE,因为 Java 是我最熟悉的语言。

I'm aware that Android comes with java.nioand java.net, as well as some org.apachepackages, but am also looking for libraries/technologies that would be possible to use with Android.

我知道 Android 带有java.nioandjava.net以及一些org.apache软件包,但我也在寻找可以与 Android 一起使用的库/技术。

So far I've not found anything massively helpful on the internet, so I'm seeing what SO can suggest.

到目前为止,我还没有在互联网上找到任何非常有用的东西,所以我看到了 SO 可以提出的建议。

Specifically I am interested in knowing:

具体来说,我有兴趣了解:

  1. What support is there for various middleware technologies in Android? e.g.
    • RPC based middleware
    • CORBA
    • Message based middleware
    • Web services such as XML-RPC, SOAP, REST
  2. How well (or not) do existing Java libraries work when used on the Android platform? (e.g. If I wanted to use a library/API designed for Java SE rather than Android what problems might I encounter?)
  1. Android 中对各种中间件技术有哪些支持?例如
    • 基于RPC的中间件
    • CORBA
    • 基于消息的中间件
    • Web 服务,例如 XML-RPC、SOAP、REST
  2. 在 Android 平台上使用时,现有 Java 库的工作情况(或不工作)如何?(例如,如果我想使用为 Java SE 而不是 Android 设计的库/API,我可能会遇到什么问题?)

Ideally, as the focus of my project isn't meant to be the communication between the server and client, I could use an existing middleware to handle the communication, but I am prepared for the worst case, which is having to write my own.

理想情况下,由于我的项目的重点不是服务器和客户端之间的通信,我可以使用现有的中间件来处理通信,但我已为最坏的情况做好了准备,即必须自己编写。

回答by CommonsWare

What support is there for various middleware technologies in Android?

Android 中对各种中间件技术有哪些支持?

My personal opinion -- though I do not feel I am alone in thinking this way -- is that only protocols specifically designed to run over the Internet are remotely suitable for use with a mobile client. So, of your list, the only one that I would even entertain would be:

我个人的观点——尽管我并不觉得只有我一个人有这种想法——只有专门设计用于在 Internet 上运行的协议才适合远程使用移动客户端。因此,在您的列表中,我什至会招待的唯一一个是:

Web services such as XML-RPC, SOAP, REST

Web 服务,例如 XML-RPC、SOAP、REST

Some people have been maintaining an Android port of kSOAP2. However, I get the distinct impression that most Android developers working in this area have tended towards REST and REST-ish protocols. If nothing else, that's what all the fun Web sites and services are using for an API, particularly compared with XML-RPC (old) and SOAP (old and icky).

有些人一直在维护 kSOAP2 的 Android 端口。但是,我有一个明显的印象,即在该领域工作的大多数 Android 开发人员都倾向于使用 REST 和 REST-ish 协议。如果不出意外,这就是所有有趣的网站和服务都用于 API 的东西,特别是与 XML-RPC(旧)和 SOAP(旧的和 icky)相比。

I have successfully used both the java.net.URLConnectionand Apache HTTPClient libraries in Android for communicating with REST-style endpoints -- both directly and through third-party JARs -- with no real Android-specific issues.

我已经成功地使用java.net.URLConnectionAndroid 中的和 Apache HTTPClient 库与 REST 风格的端点进行通信——直接和通过第三方 JAR——没有真正的 Android 特定问题。

How well (or not) do existing Java libraries work when used on the Android platform?

在 Android 平台上使用时,现有 Java 库的工作情况(或不工作)如何?

It is difficult to answer that in the abstract. Android implements a substantial subset of JavaSE, but not all of JavaSE, so there's a chance that any given JAR will expect something Android does not offer. Similarly, Android does not use environment variables, command-line switches, or a variety of other things that developers focused on the desktop might have introduced as semi-requirements. So, some things have worked for me with nothing more than a recompile (Beanshell), and some things have worked for me after removing redundant classs (JTwitter), and some things looked like they were going to be ghastly to get working (JavaMail).

很难抽象地回答这个问题。Android 实现了 JavaSE 的一个重要子集,但不是 JavaSE 的全部,因此任何给定的 JAR 都有可能期望 Android 没有提供的东西。同样,Android 不使用环境变量、命令行开关或专注于桌面的开发人员可能作为半要求引入的各种其他东西。所以,有些东西对我来说只需要重新编译(Beanshell),有些东西在删除多余的类(JTwitter)后对我有用,有些东西看起来很难工作(JavaMail) .