/Users/lyon/j4p/src/net/rmi/ComputeServer.java
|
1 package net.rmi;
2
3 import java.io.Serializable;
4 import java.rmi.RMISecurityManager;
5 import java.rmi.RemoteException;
6 import java.rmi.server.UnicastRemoteObject;
7
8 public class ComputeServer
9 extends UnicastRemoteObject
10 implements Computable {
11
12 // rmi servers must have
13 // a public constructor that throws a
14 // RemoteException
15 public ComputeServer() throws RemoteException {
16 }
17
18 //in rmi, parameters must be serializale
19 public void println(Serializable o)
20 throws RemoteException {
21 System.out.println(o);
22 }
23
24 //servers must gui.run RMIC
25 public static void main(String[] args)
26 throws RemoteException {
27 System.setSecurityManager(
28 new RMISecurityManager());
29 try {
30 lookUpServerAndBindWithRegistry();
31 } catch (Exception e) {
32 e.printStackTrace();
33 }
34 }
35
36 private static void lookUpServerAndBindWithRegistry() throws java.rmi.RemoteException, java.net.MalformedURLException {
37 ComputeServer cs =
38 new ComputeServer();
39 String url =
40 "rmi://localhost/ComputeServer";
41 java.rmi.Naming.rebind(url, cs);
42 System.out.println("server started");
43 }
44 }
45