Server Implementation

Lisitng 6.6 InfoServerImpl.java

import java.rmi.*;
import java.rmi.server.*;

//Server implementation
public class InfoServerImpl 
	extends UnicastRemoteObject
	implements InfoInterface {

//Constructor
public InfoServerImpl() 
	throws RemoteException {
	System.out.println("Creating Server Object");
}

//Remote method implementation
public String getInfo()
	throws RemoteException,ServerNotActiveException{
	String msg="CLIENT INFO\n";

	//Return the hostname of the current client.
	msg += getClientHost();
	return msg;
}

//main method
public static void main(String args[]) { 
   try { 

//create a server object InfoServerImpl obj = new InfoServerImpl(); //bind the remote object Naming.rebind("Server",obj); System.out.println("Server ready"); } catch (Exception ex) { System.out.println("Error: " + ex.getMessage()); } } }

The getInfo() method of the server calls the getClientHost() method of the RemoteServer class. The getClientHost() method returns the hostname of the current client.

 

 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com