-
Notifications
You must be signed in to change notification settings - Fork 2
/
Server.java
42 lines (36 loc) · 1.31 KB
/
Server.java
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
/*
Server.java
@author Terence Tan Boon Kiat
@guid 2228167t
Server code for hosting the AuctionSystem
*/
import java.rmi.Naming; // import naming classes to bind to rmiregistry
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.server.UnicastRemoteObject;
public class Server {
public Server(int port) {
try {
AuctionSystem si = new AuctionSystem();
AuctionSystemInterface s = (AuctionSystemInterface) UnicastRemoteObject.exportObject(si, 0);
Naming.rebind("rmi://localhost:" + port + "/AuctionSystemService", s);
System.out.println("Server is starting...");
} catch (MalformedURLException murle) {
System.out.println();
System.out.println("MalformedURLException");
System.out.println(murle);
} catch (RemoteException re) {
System.out.println();
System.out.println("RemoteException");
System.out.println(re);
}
}
public static void main(String args[]) {
// create new server for auction system
int p = 1099; // default port number
if (args.length == 1) {
p = Integer.parseInt(args[0]); // custom port number
}
new Server(p);
}
}