Java Reference
In-Depth Information
Note When reading these benefits you should be aware that the benefit might be a disadvantage of the
other choice. Also, many of the perceived benefits can be easily countered in an argument—where possible
we provide counterarguments in our discussions in the same place we discuss the benefit.
Benefits of Using a Serialized Objects Over Sockets Solution
In real-world applications, the choice between RMI and sockets often comes down to the
scalability and performance requirements of your application.
Sockets are ideal if performance is a must since you can limit the degree of overhead and
sockets are well suited for sending data, often in compressed form that does not require a
heavy protocol. As you may recall, the larger and more complex your protocol becomes, the
more you may want to use RMI. A well-designed, simple socket interface can outperform an
RMI-based server. If you must handle a large number of requests efficiently, sockets may be
for you.
This does not mean that you cannot compress or encrypt your data using RMI—if you
want to, you can use custom socket factories with RMI to provide specialist functionality (for
more information, refer to http://java.sun.com/j2se/1.5.0/docs/guide/rmi/socketfactory/ ).
However, when you implement a straightforward sockets solution, you can easily incorporate
only the functionality you need, and leave out the functionality you do not need. For example,
you might decide to drop the “heartbeat” functionality that is incorporated into every RMI
solution. The heartbeat functionality simply ensures that at regular intervals the server sends
a signal—a heartbeat—to the RMI registry to let the registry know that the server is still alive;
similarly the RMI clients send a signal—a heartbeat—to the server to let it know that they are
still alive.
Another advantage to sockets is that most system administrators are already familiar with
what needs to be done to implement a server that listens on a particular socket, even if they
need to go through a firewall. Few are familiar with setting up an RMI registry, and even fewer
know how to configure RMI to work through a firewall. RMI can work through a firewall, but it
is not quite as simple as setting up a simple sockets solution through the firewall.
Note Sockets have been a standard method of performing network connectivity for many years, whereas
RMI is a relatively new standard. However, this alone does not justify using sockets over RMI; using serial-
ized objects over the sockets connection almost ensures that only another Java class can connect to your
server (only “almost” because the Java specifications make it explicitly clear how a serialized class will
appear, which means it is possible for somebody to develop a client in a different language—just very diffi-
cult). Conversely, using RMI over IIOP (the Internet Inter-Orb Protocol used by CORBA) would allow any
CORBA-compliant client to connect to your server (although using RMI over IIOP is not allowed in the
current assignments). For more information on IIOP and CORBA, refer to the Wikipedia pages http://
en.wikipedia.org/wiki/IIOP and http://en.wikipedia.org/wiki/CORBA , respectively.
Search WWH ::




Custom Search