Select Git revision
Server.java 2.19 KiB
package server;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Scanner;
import remote.IClientController;
import remote.IDrawingController;
public class Server extends Observable {
public static void main(String[] args) {
try {
//Export the remote math object to the Java RMI runtime so that it
//can receive incoming remote calls.
//Because RemoteMath extends UnicastRemoteObject, this
//is done automatically when the object is initialized.
//
//RemoteMath obj = new RemoteMath();
//IRemoteMath stub = (IRemoteMath) UnicastRemoteObject.exportObject(obj, 0);
//
IDrawingController drawingController = new DrawingController();
IClientController clientController = new ClientController();
//Publish the remote object's stub in the registry under the name "Compute"
Registry registry = LocateRegistry.getRegistry();
registry.rebind("DrawingController", drawingController);
registry.rebind("ClientController", clientController);
System.out.println("Server is ready");
// Test client update command
// Get client registry
ArrayList<String> usernameList = new ArrayList<>();
Scanner keyboard = new Scanner(System.in);
String command;
while(true) {
command = keyboard.nextLine();
switch (command) {
case "test1":
usernameList = clientController.getUsernameList();
if (!usernameList.isEmpty()) {
for (int i = 0; i < usernameList.size(); i++) {
System.out.println(usernameList.get(i));
}
}
break;
default:
System.out.println("nothing");
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}