/**
 * @author Dr. Haiping Xu
 * Created at the CIS Department, UMass Dartmouth
 */

import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;

public class BBSClient {

    public static void main(String[] args) {
       BBSInterface bbsServer;
       Registry registry;
       String serverAddress=args[0];
       String text1 = args[1];
       String text2 = args[2];

       String serverPort = "8686";
       String phrase = "";

       //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
           bbsServer= (BBSInterface)(registry.lookup("BBSServer"));

           // call the remote method
           for (int i = 0; i < 10; i++) {

               System.out.print("write: " + text1 + " " + text2 + " -> wait ... ");
               bbsServer.write(text1, text2);
               phrase = bbsServer.read();
               System.out.println("-> read: " + phrase);
           }

       } catch(RemoteException e){
           e.printStackTrace();
       } catch(NotBoundException e){
           e.printStackTrace();
       }
    }
}

