K. Tsang wrote:Hello Buler,
To get the registry working, you need to change your server class to create the registry
I used rebind rather than bind but I don't think it matter much. Also the "Hello" is suppose to be the server RMI path which looks like "rmi://<ip address>:<port> <name>". So yours should really looks like "rmi://192.168.x.x:1099 Hello".
Just to give you a pointer about RMI, if you bind with IP address on the server then the client must get the registry using IP address. If use hostname then both sides use hostname. Also for IP address binding with "127.0.0.1" vs "192.168.x.x" is a big difference. 127.0.0.1 only allow both server and client to run on same machine. 192.168.x.x allows you to run server and client on different machines - like unix server and windows client.
Hello K.Tsang,
Thank you for your reply. I've solved the problem after running your code. I continued to search the Sun's RMI tutorial , I found another problem about the use of RMI.
Do I have to create and install a Security Manager when the server and client class are called? Do I need to know very well about the knowledge of IP address for this exam? e.g. "127.0.0.1" vs "192.168.x.x"
I've modified above code so that a Security Manager can be installed in both of classes' main method. The server class run fine. Unfortunately, I came up with the following exception when I run the client class:
Client exception: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at example.hello.Client.main(Client.java:55)
Is there any method to solve it?
Server class:
Client class: