Java standard for client / server interaction

What is the “official” Java API for client / server communications or P2P? Java RMI? Some other network APIs

Is this official network API the standard for both SE and EE?

I'm sure the answer is very context, so let's take a look at a few instances:

  • You have 2 swing clients installed on 2 computers and connected to the same network (or the Internet), and you want any of them to send another primitive, for example an integer 4 or some POJO, for example, Widget "
  • Same as # 1 above, but between the Swing client and fully compatible Java EE internal content (implementation of managed beans, application servers, only nine yards)

I don’t have a specific application, I’m just wondering what are the “norms” for client-client and client-server interaction in the Java world.

+7
source share
5 answers

If binding to Java is not a problem, RMI is a rather abstract solution when it comes to “exchanging” data with the client and server (especially when the data is Java classes that can be difficult / too much effort to represent text data) . Just make sure your object implements Serializable, and almost anything can be transmitted by cable.

If this does not match your score and you want to reset the source network materials, the Netty client-server socket infrastructure is a pretty good choice.

+3
source

There is no such thing as the most official network API in J2SE; all J2SE APIs are official in the sense that they are supported by Sun (now Oracle).
However, you should choose your API based on the following criteria:

  • You (or your team) know how to use a specific API;
  • As a simple / complex API to use;
  • What bandwidth are you targeting? For applications with a high degree of sensitivity, you can use the binary protocol. For other cases, you can use the text protocol.

For example, between two clients, a simple text protocol is enough to transmit POJO, for example, using Apache MINA or Google protocol buffers.
This will also work between client and server.


Answer Zac's questions in a comment:

  • The increase in the performance of binary protocols is due to the fact that you do not need to convert everything to text form and vice versa - you can simply transfer a binary presentation of your application memory with minimal changes, for example, in the case of the BSD Sockets API, conversion from host byte to network byte order. Unfortunately, I don’t know the details of how RMI / Java serialization objects process objects, but I’m sure that it is still much faster than transferring all data in a human-readable form;
  • Yes, MINA and protocol buffers have Java APIs. They simply are not part of the Java SE package, you must download them separately. By the way, MINA can use both binary and readable serialization, depending on how you use it.
  • You must define the concept of "good" somehow, for example, by answering the questions mentioned above. If you want to use objects over the network, use RMI. If you do not, Netty or MINA is enough, no matter what you learn.
+1
source

For P2P, Sun at one point pressed JXTA hard.

I would not risk using RMI for P2P communication.

0
source

rmi is pretty much the standard java protocol for java. It is built-in and very easy to use. most j2ee backends also exchange data using rmi, although this is not the only possibility.

0
source

J2SE is the most common, probably RMI or raw sockets.

J2EE uses a messaging bus that all (servers and clients) subscribe to, which are very different from rmi-style solutions (although at the lowest level, an implementation can still rely on RMI). This helps automate redundancy and fault tolerance. If you need this functionality, I believe that it can also be used in SE.

I have not used J2EE for a long time, so this may have changed, but I doubt it. The messaging system was a core component of J2EE.

-one
source

All Articles