-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteClient.java
More file actions
37 lines (28 loc) · 1.13 KB
/
RemoteClient.java
File metadata and controls
37 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;
public class RemoteClient extends UnicastRemoteObject implements ClientIn {
private ServerIn server;
Scanner in = new Scanner(System.in);
public RemoteClient() throws RemoteException {
}
@Override
public void sendMessage(String name, String message) throws RemoteException, NotBoundException {
server.boardCastToAll(message, name);
server.clientToAll(name, name + ": " + message);
}
@Override
public void receiveMessage(String message) throws RemoteException {
System.out.println(message);
}
public void startClient(String name) throws RemoteException, NotBoundException, AlreadyBoundException {
Registry registry = LocateRegistry.getRegistry(Server.hostname, Server.port);
server = (ServerIn)registry.lookup("Server");
server.setNameAndId(name, server.getId());
server.welcome(name);
}
}