Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI vs Socket Programming

 
Joviec chen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

regards,
Jovie
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he asked it because of the SCJD.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
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
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Totally missed that! LOL
The sheriff is the person with the sharpest eyes, as it should be.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic