我的项目是客户端/服务器,客户端将对象发送到服务器并且服务器响应,所有这些都是由RMI
客户项目
//界面
public interface RMI_INTERFACE extends Remote
{
public int Add(Employee e) throws RemoteException;
}
//我需要发送它的类
public class Employee implements Serializable
{
int ID;
String Name;
int Salary;
public Employee(int id,String name,int salary)
{
ID=id;
Name =name;
Salary=salary;
}
}
//客户端
public class RMI_CLIENT
{
public RMI_CLIENT()
{
}
public static void main(String[] args) {
try {
String name = "RMI_INTERFACE";
Registry registry = LocateRegistry.getRegistry("localhost",5000);
RMI_INTERFACE si = (RMI_INTERFACE) registry.lookup(name);
int ii;
for (Integer i=0 ;i<10;i++)
{
Employee e= new Employee(i, "employee"+i.toString() , i*1000+100);
ii=si.Add(e);
System.out.println(ii);
}
// int pi = si.Get_Salary(s);
} catch (Exception e) {
System.err.println(e.getCause());
}
}
}
//服务器项目
//界面 公共接口RMI_INTERFACE扩展了Remote {
public int Add(Employee e) throws RemoteException;
}
//我将发送并接收它的类 公共类Employee实现Serializable { int ID;
String Name;
int Salary;
public Employee(int id,String name,int salary)
{
ID=id;
Name =name;
Salary=salary;
}
}
//用于保存所有收到的对象的类 公共课Maneger {
static Employee [] employee_arr = new Employee[10];
static int i=0;
Maneger (Employee e)
{
employee_arr[i]=e;
i++;
}
public int Get_Index ()
{
return i;
}
}
//服务器 公共类RMI_SERVER扩展UnicastRemoteObject实现RMI_INTERFACE {
RMI_SERVER() throws RemoteException
{
super();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// TODO code application logic here
String name = "RMI_INTERFACE";
RMI_INTERFACE si = new RMI_SERVER();
Registry registry = LocateRegistry.createRegistry( 5000 );
registry.rebind(name, new RMI_SERVER() );
System.out.println("Server is running ...");
}
catch (Exception e) {
System.err.println("ComputeEngine exception:");
}
}
@Override
public int Add(Employee e) throws RemoteException {
Maneger m =new Maneger(e);
return m.Get_Index();
}
}
当我运行客户端时出现此错误:java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法
答案 0 :(得分:0)
您已更改远程对象或远程接口,但尚未重新编译并重新部署所有受影响的.class文件。