Server Implementation

Listing 10.2 SingleThreadImpl (Complete server code)

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

//server implementation
public class SingleThreadImpl extends 
	UnicastRemoteObject 
	implements SingleThreadInterface{
		
    //constructor
    public SingleThreadImpl()
	throws RemoteException{
			
	System.out.println("Creating server object");
    }

    //remote method implementation
    public String dangerousLoop()
	throws RemoteException{
	
	//waste some time.
	for(int i=0;i<5000;i++){
	   System.out.println("value of i= " +i);
	}
	return "Dangerous loop";
    }

   public static void main(String args[]){
	try{
	 
	 //remote object
	 SingleThreadImpl obj = new SingleThreadImpl();
	 
	 //bind the specified name to 
	 //a new remote object. 
	 Naming.rebind("Server",obj);
	}catch(Exception ex){
		System.out.println(ex.getMessage());
	}
    }
}

The server provides implementation for the dangerousLoop() method. The method simply prints 0 to 4999 and returns a string.

 

 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com