-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServer.java
More file actions
72 lines (60 loc) · 2.2 KB
/
Server.java
File metadata and controls
72 lines (60 loc) · 2.2 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.ExportException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;
public class Server extends ImplMatch {
public Server() {}
public static void main(String args[]) {
if (args.length < 1) {
System.out.println("Please provide a valid server number!");
System.exit(1);
}
Scanner sc = new Scanner(System.in);
Registry registry = null;
try {
registry = LocateRegistry.createRegistry(1099);
} catch(ExportException ee) {
try{
registry = LocateRegistry.getRegistry(1099);
} catch(Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
System.err.println("Port already in use, Attempting to use the open registry");
} catch(Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
try {
// Instantiating the implementation class
ImplMatch obj = new ImplMatch();
// Exporting the object of implementation class
// (here we are exporting the remote object to the stub)
UtilsClass stub = (UtilsClass) UnicastRemoteObject.exportObject(obj, 0);
registry.rebind("Dream11-node" + args[0], stub);
System.err.println("Dream11-node" + args[0] +" ready!");
String command="";
boolean flag=true;
while(sc.hasNextLine() && flag) {
command = sc.next();
switch(command) {
case "exit":
case "quit":
case "q":
System.exit(0);
break;
case "load":
stub.AddMatch(0, "", false, "127.0.0.1");
stub.LoadMatch(0);
break;
default:
System.err.println(command);
}
}
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}