[英]Java standard for client/server communication
What is the "official" Java API for client/server or P2P communication? 什么是客户端/服务器或P2P通信的“官方”Java API? Java RMI?
Java RMI? Some other networking API??
其他一些网络API?
Is this official networking API the standard for both SE and EE? 这是官方的网络API为SE和EE标准?
I'm sure the answer is very context-specific, so let's take a look at a few instances: 我确定答案是特定于上下文的,所以我们来看看几个实例:
I don't have a specific application in mind, I'm just wondering what are the "norms" for client-client and client-server communication in the world of Java. 我没有考虑具体的应用程序,我只是想知道Java世界中客户端 - 客户端和客户端 - 服务器通信的“规范”是什么。
If being bound by Java isn't a problem, RMI is a pretty abstracted solution when it comes to the client and server solution "exchanging" data (especially when the data is Java classes which might be difficult/too much effort to represent as textual data). 如果受Java约束不是问题,那么当客户端和服务器解决方案“交换”数据时,RMI是一个非常抽象的解决方案(特别是当数据是Java类时,可能很难/太多努力表示为文本数据)。 Just make sure your object implements Serializable and almost anything can be transmitted over the wire.
只需确保您的对象实现Serializable,几乎任何东西都可以通过网络传输。
If this doesn't fit your bill and you want to drop down the raw networking stuff, the client-server socket framework Netty is a pretty good choice. 如果这不适合您的账单,并且您想要删除原始网络内容,那么客户端 - 服务器套接字框架Netty是一个不错的选择。
There's no such thing as the most official networking API in J2SE, all J2SE APIs are official in the sense they are supported by Sun (now Oracle). 在J2SE中没有最官方的网络API,所有J2SE API都是官方的,因为Sun(现在是Oracle)支持它们。
That said, you should choose your API based on following criteria: 也就是说,您应该根据以下标准选择API:
For example, between two clients simple text-based protocol will suffice for passing POJOs, for example using Apache MINA or Google protocol buffers. 例如,在两个客户端之间,简单的基于文本的协议就足以传递POJO,例如使用Apache MINA或Google协议缓冲区。
This will work between client and server as well. 这也适用于客户端和服务器。
Response to Zac's questions in comment: 回应Zac的评论问题:
rmi is pretty much the standard java to java protocol. rmi几乎是标准的java to java协议。 it's built in and very simple to use.
它内置并且使用起来非常简单。 most j2ee backends also communicate using rmi, although that's not the only possibility.
大多数j2ee后端也使用rmi进行通信,尽管这不是唯一的可能性。
J2SE the most common is probably RMI or raw sockets. J2SE最常见的可能是RMI或原始套接字。
J2EE uses a messaging bus that everyone (servers and clients) subscribes to which is quite different from rmi style solutions (although at the lowest level an implementation may still rely on RMI). J2EE使用每个人(服务器和客户端)订阅的消息传递总线,这与rmi样式解决方案完全不同(尽管在最低级别,实现可能仍然依赖于RMI)。 It helps automate redundancy and failover.
它有助于自动化冗余和故障转移。 If you need this functionality I believe it can be used in SE as well.
如果您需要此功能,我相信它也可以在SE中使用。
I haven't used J2EE for quite a while now, so this may have changed, but I doubt it. 我现在还没有使用J2EE很长一段时间,所以这可能已经改变了,但我对此表示怀疑。 The messaging system was a core component of J2EE.
消息传递系统是J2EE的核心组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.