package chat;

import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.*;
import java.io.*;


public class ChatClientImpl extends UnicastRemoteObject implements ChatClient
{
	public ChatClientImpl() throws RemoteException
	{
	}
	
	public void printMessage(String message)
	{
		System.out.println(message);
	}
	
	public static void main(String [] args)
	{
	     try
	     {
		  String name = args[0];
//		  String contato;

		  ChatClientImpl client = new ChatClientImpl();
		  ChatClientImpl usuario = new ChatClientImpl();

                  ChatServer server = (ChatServer)Naming.lookup("//localhost:1234/chatserver");
                             		  	
		  	try
		  	{
  	  		 server.enter(args[0],client);
		  	 BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
			 while(true)
		     	  {
		     	  	System.out.print("Contato: ");
	     		  	String contato = read.readLine();
		     	  	System.out.print("\nmsg: ");
	     		  	String msg = read.readLine();
	     	  		server.sendMessage(name,msg);

	     	  	  }
		  	}
		  	catch(RemoteException e)
     	  {
     	  	System.out.println(e);
     	  }
     }
     catch(Exception e){System.out.println(e);}
	}
}
