wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes difference between socket programming and rmi in java?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "difference between socket programming and rmi in java??" Watch "difference between socket programming and rmi in java??" New topic
Author

difference between socket programming and rmi in java??

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
i want to know, is there any difference between rmi and socket programming??
there is lot of things which we do in socket programming manually, that we don't need to do in rmi manually, is this the only difference or m i wrong??
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
RMI means Java on both sides, which may or may not be an issue in your case. It also means you may have to keep the JVMs on both sides at the same Java version (RMI uses binary serialization underneath, and that tends not to work if the JVMs on either end are of different versions). Frankly, I can't imagine a scenario where I'd use RMI these days and not go for a REST API using Jersey or Restlet. Those also have high-level Java bindings, but provide much more architectural flexibility.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

RMI is built on top of sockets. It translates method calls and return values and sends those through sockets.

If you want you can even tweak the sockets used by RMI. There are interfaces RMIClientSocketFactory and RMIServerSocketFactory which are used to create the sockets and server sockets. By creating your own implementations (easiest is to extend RMISocketFactory) and supplying it when exporting your remote objects your own sockets are used. One example would be SslRMIClientSocketFactory / SslRMIServerSocketFactory for using RMI over SSL.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
so it means, basically objective of both are same, i mean both do the same job, isn't it??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:so it means, basically objective of both are same, i mean both do the same job, isn't it??


No.

Sockets are used for transferring data, usually between two different computers. The data can be in any protocol imaginable, can have any semantics imaginable, and the programs sending and receiving the data can both be Java, or one of them can, or neither.

RMI is a Java-specific protocol for (as the name implies) invoking a method in a different Java process, usually on a different computer. It is, as already stated, built on top of sockets.

Saying they're both "basically the same" is like saying an application written in Java is basically the same as the Java language.
 
Don't get me started about those stupid light bulbs.
 
subject: difference between socket programming and rmi in java??