|
||||
|
The GreaterServerImpl class is not extending the UnicastRemoteObject. |
The constructor for this class simply prints a small message.
//constructor
public GreaterServerImpl()
throws RemoteException{
System.out.println("Creating server object");
}
Here is the implementation for the getGreater() method, which compares two given numbers and returns the greater number.
//remote method called by clients
public String getGreater(int one,int two)
throws RemoteException{
if(one > two)
return one +" is greater";
else if(two > one)
return two +" is greater" ;
else
return "Equal" ;
}
The main method of the server creates one or more instances of the remote object implementation, which provides the service. For example:
GreaterServerImpl obj = new GreaterServerImpl();
The following line explicitly exports the remote object to make it available to receive incoming calls, using an anonymous port.
//explicitly exporting remote
object
UnicastRemoteObject.exportObject(obj);
Rebinding the specified name to a remote object.
//bind with the regsitry service
Naming.rebind("Server",obj);