Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package RMIChat;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.rmi.*;
- import java.rmi.server.UnicastRemoteObject;
- import java.util.Scanner;
- /**
- *
- * @author Jay
- */
- public class ChatClient extends UnicastRemoteObject implements Runnable, ChatService {
- public ChatClient() throws RemoteException {
- super();
- }
- private ChatServer mycs;
- public void ChatClientImp(ChatServer cs) throws RemoteException
- {
- mycs = cs;
- mycs.regClient(this);
- }
- public synchronized void getMessage(String s) throws RemoteException {
- System.out.println("Message: " + s);
- }
- public void run()
- {
- Scanner in = new Scanner(System.in);
- String msg;
- while(true)
- {
- try
- {
- msg = in.nextLine();
- mycs.broadcast(msg);
- }
- catch (Exception e)
- {
- System.out.println("A problem occured!");
- }
- }
- }
- public static void main(String[] args)
- {
- String url = "rmi://localhost/ChatServer";
- try
- {
- ChatServer cs = (ChatServer) Naming.lookup(url);
- ChatClient cc = new ChatClient();
- // new Thread(new ChatClientImp(cs)).start();
- } catch (Exception e) {
- System.out.println("Problem... :"+e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement