my project is client/server that client send an object to the server and server respond, all that by RMI
client project
// the interface
public interface RMI_INTERFACE extends Remote
{
public int Add(Employee e) throws RemoteException;
}
// the class that i need to send it
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;
}
}
//the client
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());
}
}
}
//server project
//the interface public interface RMI_INTERFACE extends Remote {
public int Add(Employee e) throws RemoteException;
}
//class that i will send it and receive it 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;
}
}
//class to hold all received objects public class 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;
}
}
//the server public class RMI_SERVER extends UnicastRemoteObject implements 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();
}
}
when i run client appear this error : java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object