RMI exception: Error unmarshalling return header; nested exception is:问题

gengxinzhou1111 gengxinzhou1111 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
新接触 按照教程 调试了一下午 最后归结到这个错误。。
客户机和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();
}
}





}
...全文
评论 3
收藏 已收藏
分享
返回顶部
gengxinzhou1111
Java EE 67,535 成员 225,843 内容