// here HelloInterface definition is required by Hello Class only for compilation
No. It is also required by HelloServer
and HelloClient
for compilation, and it is required at runtime as well, by both the server and the client, and also by the RMI Registry.
stub/skeleton classes also get generated here in machine2.
No. RMI skeletons have been obsolete since 1998. You didn't generate one at all, unless you used the rmic
option -v1.1
or -vcompat,
and you don't need to use either. You don't even need to use rmic
itself at all since Java 1.5, if you just add super(0)
to your Hello
constructor.
I copied
Hello_stub.class
in to machine1/folder1
You also need HelloInterface.class
here.
HelloClient.class on machine1 is using Hello_stub.class when we invoke hello.say() from client program to communicate with machine2
Correct.
[I] am not clear at which instance Hello_skel.class on machine 2 is invoked by HelloServer.class
It isn't invoked at all, unless you used rmic -v1.1,
in which case it is invoked by RMI to mediate between the RMI runtime system and the Hello
object. It doesn't have anything to do with the HelloServer
class at all.
Coming from socket programming background in C, How do i visualise socket()/connect() part of client program
RMI creates connections as needed, pools them, and closes them when they've been idle. There is a connection required to call Naming.lookup(),
and another one to call the remote method.
and socket()/bind()/listen()/accept() pasrt of server program in this RMI framework?
Exporting a remote object creates a listening socket, or shares one that has already been created by RMI. The RMI runtime system calls accept(),
works out from the request header which remote object it's for, and calls that remote object via reflection (or the old skeleton) with the arguments in the request, and sends the result or exception if any back to the client.
NB:
You don't need a
SecurityManager
or a .policy file or the-Djava.security.policy
argument unless you're using the RMI codebase feature, and you aren't.I don't see what the
msg
parameter and instance member is for inHello.
You aren't using it.You don't really need
HelloServer.
You could put thatmain()
method intoHello.
Your client doesn't call any remote methods on the object it looks up. Presumably you want to add that?