public interface IExample extends Remote {
public String getMessage(String input) throws RemoteException;
}
public class ExampleImpl extends UnicastRemoteObject implements IExample {
public ExampleImpl() throws RemoteException {
super();
}
@Override
public String getMessage(String input) throws RemoteException {
return "Hi " + input + "!!!";
}
public static void main(String... args) throws RemoteException, MalformedURLException {
System.setSecurityManager(new RMISecurityManager());
String name = "myexample";
IExample engine = new ExampleImpl();
IExample stub =
(IExample) UnicastRemoteObject.exportObject(engine, 1090);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub);
}
}
P.S。感谢所有人,对不起我的英语。 P.p.s.而对于我的愚蠢问题。
答案 0 :(得分:0)
扩展UnicastRemoteObject的类会在构造时自动导出。你不必自己动手。删除exportObject()调用。