// FooClient.java

import java.rmi.*;
import java.math.*;

public class FooClient {
	public static void main(String args[]) {
		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new RMISecurityManager());
		}
		try {
			String name = "//" + args[0] + "/" + FooRemote.SERVICE;
			
			// Get the stub for the server object
			FooRemote foo = (FooRemote) Naming.lookup(name);			
		
			// Send the server a message
			String[] result  = (String[]) foo.doit();
			Log.print("Client: received from server -- " + result[0] + result[1]);
			
			
			// Create a pipe here and send it to the server
			PipeRemote pipe = new PipeServer();
			foo.install(pipe);
			
			// This will call us back on the pipe
			foo.doit();

			
			// Remove their ref back to us, so we can exit
			foo.install(null);

			// 
			System.exit(0);
				
		} catch (Exception e) {
			System.err.println("FooClient exception: " + 
				e.getMessage());
			e.printStackTrace();
		}
		
		Log.print("Client: done");
	}
}
