/**
 * @author Dr. Haiping Xu
 * Created at the CIS Department, UMass Dartmouth
 */

import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;

public class RMIClient {

    public static void main(String[] args) {
       ReceiveMessageInterface rmiServer;
       Registry registry;
       String serverAddress=args[0];
       String serverPort=args[1];
       String text=args[2];
       System.out.println("Sending " + text + " to " + serverAddress + ":" + serverPort);
       try{
           // get the registry
           int port = (new Integer(serverPort)).intValue();
           registry = LocateRegistry.getRegistry(serverAddress, port);

           // look up the remote object
           rmiServer= (ReceiveMessageInterface)(registry.lookup("RMIServer"));

           // call the remote method
           rmiServer.receiveMessage(text);

       } catch(RemoteException e){
           e.printStackTrace();
       } catch(NotBoundException e){
           e.printStackTrace();
       }
    }
}

