📄 readme
字号:
Simple RMI example code - this is an alternative implementation in which
the remote object implementation class RemoteMathImpl does not extend
UnicastRemoteObject but instead uses the static method exportObject()
of UnicastRemoteObject to create a remote object (register with the
name registry, etc.). Other than this minor difference - the code is
the same as in the SimpleRMI example. Note that there is no difference
to the client - the code is identical.
RemoteMath.java is the definition of an interface that extends Remote.
Any object that will be available as a remote object must implement Remote,
or an interface that implements the Remote interface.
RemoteMathImpl.java is the implementation of the RemoteMath interface. This
class provides the actual remote methods. In this simple example the RemoteMathImpl
class also includes a main() that creates a remote object and registers with the
naming service so clients can find it.
RemoteMathImpl_Stub.class is created by rmic (the rmi compiler) based on the
RemoteMathImpl class. The stubs defined in this class are what the client
"really" calls, they take care of sending the method invocation to the server
and retrieving the result. This whole process is transparent to the programmer,
you need to generate this file, but you don't need to know what happens inside
it!
RemoteMathImpl_Skel.class - server skeleton created by the rmi compiler.
RClient.java is the source for the client program. This client takes 3 command
line parameters - the hostname of the machine running the server (the remote
methods) and 2 integers. The client runs each of the remote methods on the
2 numbers and prints out the results.
To run this example:
1. compile the files RemoteMath.java, RemoteMathImpl.java and RClient.java.
> javac RemoteMath.java RemoteMathImpl.java RClient.java
2. Run the rmi compiler to generate the stubs and skeletons:
> rmic RemoteMathImpl
3. on the machine you want to run the server (the remote methods), start up
the RMI registry (for Windows systems you use "start" to put this in the background)
> start rmiregistry
4. on the server machine you now run the server:
> java RemoteMathImpl
5. on the client machine you run the client:
> java RClient servername 12 14
You can use the same machine for the client and server by using the
hostname "localhost", as in the following example:
> java RClient localhost 22 37
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -