jQuery in Action, 3rd edition
The moose likes Distributed Java and the fly likes RMI vs Socket Programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI vs Socket Programming" Watch "RMI vs Socket Programming" New topic

RMI vs Socket Programming

Joviec chen

Joined: Oct 19, 2005
Posts: 1

I would like to develop an application in a distributed computing environment. In my system, several clients have to communicate with the server simulateneously, and some network management functionality may need to be supported by my system.

Could anyone please tell me which would be the more suitable technology to be used -- RMI or Socket programming? If I have to run multithreading, RMI or socket programming which would work better?

Thank you.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
How much of the wheel are you willing to invent?
Java programmers have been thinking about this sort of thing for a long time and have come up with pretty good solutions. You really should look into them before getting out the socket "hand-tools."
RMI is probably the most primitive - it is the basis for more advanced toolkits such as JMS, JINI and JavaSpaces.
JMS - Java Message Service - could be exactly what you want
JINI - JavaSpaces - very flexible and tolerant of network changes
SOAP - web services - only if your clients need to go through firewalls with HTTP but still a possibility
All of the above are designed for "simultaneous" multiple clients.
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 423
I think he asked it because of the SCJD.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
I can at least do you the favour of debunking any myths that socket programming is much more efficient and much faster than RMI.
By implementing the java.io.Externalizable interface and implementing your own serialization, RMI becomes as fast as the "homegrown" solutions I have seen. Another advantage is that RMI is a more mature technology and thus more tested (and debugged).
Concerning multithreading and RMI: In modern JVMs, each invocation on an RMI server is, as far as I remember, handled in a separate thread. You don't have to create threads etc, but you will have to make your classes in the server thread-safe.
Good luck with the development!
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

William Brogden wrote:How much of the wheel are you willing to invent?
.... You really should look into them before getting out the socket "hand-tools."

At this point, the proper term is "re-invent".

And don't forget REST, which has 99% of the good things of SOAP without the bad.

To reinforce what @william wrote, I can't imagine a new effort using either RMI or raw sockets. The point of OO programming is to get software reuse.

If you really, really have to use RMI over SOAP/REST for some performance reason, you know enough to do the real engineering to decide on the answer.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Before anyone spends more time on this, please note that the question is more than 3 years old, and that the topic starter hasn't posted here since.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
Totally missed that! LOL
The sheriff is the person with the sharpest eyes, as it should be.
I agree. Here's the link: http://aspose.com/file-tools
subject: RMI vs Socket Programming
It's not a secret anymore!