Advertisement
Jay_

ChatClient

Nov 27th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. package RMIChat;
  2.  
  3. /*
  4.  * To change this template, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. import java.rmi.*;
  8. import java.rmi.server.UnicastRemoteObject;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author Jay
  14.  */
  15. public class ChatClient extends UnicastRemoteObject implements Runnable, ChatService {
  16.    
  17.     public ChatClient() throws RemoteException {
  18.         super();
  19.     }
  20.    
  21.    
  22.     private ChatServer mycs;
  23.    
  24.     public void ChatClientImp(ChatServer cs) throws RemoteException
  25.     {
  26.         mycs = cs;
  27.         mycs.regClient(this);
  28.     }
  29.    
  30.     public synchronized void getMessage(String s) throws RemoteException {
  31.         System.out.println("Message: " + s);
  32.     }
  33.    
  34.     public void run()
  35.     {
  36.         Scanner in = new Scanner(System.in);
  37.         String msg;
  38.         while(true)
  39.         {
  40.             try
  41.             {
  42.                 msg = in.nextLine();
  43.                 mycs.broadcast(msg);
  44.             }
  45.             catch (Exception e)
  46.             {
  47.                 System.out.println("A problem occured!");
  48.             }
  49.         }
  50.     }
  51.    
  52.     public static void main(String[] args)
  53.     {
  54.         String url = "rmi://localhost/ChatServer";
  55.         try
  56.         {
  57.             ChatServer cs = (ChatServer) Naming.lookup(url);
  58.            
  59.             ChatClient cc = new ChatClient();
  60.  //           new Thread(new ChatClientImp(cs)).start();
  61.         } catch (Exception e) {
  62.             System.out.println("Problem... :"+e);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement