Hello All, I'm a RMI newbie and I have a the following files on one linux box:
Hello.class HelloImpl.class HelloImpl_Skel.class
Hello.java HelloImpl.java HelloImpl_Stub.class
On machine A (Server) ..../public_html/myRMI
================================================
import java.rmi.*;
public interface Hello extends java.rmi.Remote {
String sayHello() throws RemoteException;
}
================================================
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl
extends UnicastRemoteObject
implements Hello
{
private String name;
public HelloImpl(String s) throws RemoteException {
super();
name = s;
}
public String sayHello() throws RemoteException {
return "Hello World!";
}
public static void main(String args[])
{
// Create and install a security manager
System.setSecurityManager(new RMISecurityManager());
try {
HelloImpl obj = new HelloImpl("HelloServer");
Naming.rebind("//XXX.X.X.XX/~USERID/myRMI/HelloServer", obj);/ln25
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println("HelloImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
========================================================
And machine B (Client) the following files:
Hello.java Hello.class HelloImpl.class HelloMain.java HelloMain.class
java.policy
=================================================
import java.awt.*;
import java.rmi.*;
public class HelloMain {
String message = "";
public static void main(String[] args ) {
// Create and install a security manager
if(System.getSecurityManager()==null)
System.setSecurityManager(new RMISecurityManager());
try {
Hello obj = (Hello)Naming.lookup("//xxx.x.x.xx/~/userId/myRMI/HelloServer"); //this is line 11
System.out.println( obj.sayHello());
} catch (Exception e) {
System.out.println("HelloApplet exception:"+ e.getMessage());
e.printStackTrace();
}
}
}
====================================================
java.policy file:
grant {
permission java.net.SocketPermission "*:1024-65535","connect,accept";
permission java.net.SocketPermission "*:80" , "connect" ;
};
=====================================================
Server output:
COMMAND LINE INPUT ENTERED=>
java -Djava.security.policy=java.policy HelloImpl &
OUTPUT:
[1] 3500
DBowen@linux:~/public_html/myRMI> HelloImpl err: access denied (java.net.SocketPermission (theServerIP):1099 connect,resolve)
java.security.AccessControlException: access denied (java.net.SocketPermission (theServerIP):1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.connect(Socket.java:420)
at java.net.Socket.connect(Socket.java:376)
at java.net.Socket.<init>(Socket.java:291)
at java.net.Socket.<init>(Socket.java:119)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at HelloImpl.main(HelloImpl.java:25)
Client output:
COMMAND LINE INPUT=>
java -Djava.rmi.server.codebase=(theServerIP)/~DBowen/myRMI -Djava.security.policy=java.policy HelloMain
java.rmi.NotBoundException: ~/DBowen/myRMI/HelloServer
The two machines are both running linux on the same network....
I appreciate any help that can be given. Thanks
......
at java.rmi.Naming.lookup(Naming.java 84)
at HelloMain.man(HelloMain.java:11)