RMI exception: Error unmarshalling return header; nested exception is:问题
新接触 按照教程 调试了一下午 最后归结到这个错误。。
客户机和server端接口
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
服务器端实现类
import java.rmi.registry.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject
implements Hello {
public HelloImpl() throws RemoteException {
super();
}
public String sayHello () {
return "Hello World!";
}
public static void main (String args []) {
// Create and install a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
HelloImpl obj = new HelloImpl();
Registry r = LocateRegistry.createRegistry(6566);
r.bind("HelloServer", obj);
// Bind this object instance to the name "HelloServer"
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println("HelloImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
客户端调用类
import java.rmi.* ;
import java.net.* ;
import java.io.*;
import java.rmi.registry.*;
public class HelloApplet {
public static void main(String[] args)
{
Hello obj = null ;
try {
Registry r = LocateRegistry.getRegistry("113.55.35.206", 6566);
obj= (Hello) r.lookup("/HelloServer");
String message = obj.sayHello();
System.out.println("message"+message);
} catch (Exception e) {
System.out.println("HelloApplet exception: " +
e.getMessage());
e.printStackTrace();
}
}
}