Remote 1 import java rmi Remote import java Slides: 41 Download presentation Remoteインタフェース (1) import java. rmi. Remote; import java. rmi. Remote. Exception; public interface Hello extends Remote { public String say. Hello() throws Remote. Exception; } サーバ側のプログラム (1) クラスの定義 public class Hello. Impl extends Unicast. Remote. Object implements Hello {. . . } サーバ側のプログラム (3) コンストラクタとメソッド public Hello. Impl() throws Remote. Exception { super(); } public String say. Hello() throws Remote. Exception { return "Hello world!"; } サーバ側のプログラム (5) mainメソッド (1) // 許可されてない操作を行わないために if (System. get. Security. Manager() == null) { System. set. Security. Manager( new RMISecurity. Manager() ); } サーバ側のプログラム (6) mainメソッド (2) // インスタンスを生成 Hello. Impl obj = new Hello. Impl(); // rmi: //localhost/Hello. Server といった // URIを生成する String. Buffer url = new String. Buffer(); url. append("rmi: //"); url. append(args[0]); url. append("/Hello. Server"); サーバ側のプログラム (7) mainメソッド (3) // rmiregistry に // Hello. Impl を // rmi: //localhost/Hello. Server という名前で // 登録する Naming. rebind(new String(url), obj); クライアント側のプログラム (1) // rmi: //localhost/Hello. Server といった // URIを生成する String. Buffer url = new String. Buffer(); url. append("rmi: //"); url. append(args[0]); url. append("/Hello. Server"); クライアント側のプログラム (2) // rmiregistry から // rmi: //localhost/Hello. Server という名前の // オブジェクトを探し、Hello にキャストする Hello obj = (Hello)Naming. lookup( new String(url)); プログラムのコンパイル n n n javac Hello. Impl. javac Hello. Client. java サーバの起動 (1) コマンドライン java -Djava. rmi. server. codebase= file: ///C: Homermi -Djava. security. policy=policy. txt Hello. Impl localhost サーバの起動 (6) policy. txt の内容 grant { // Allow everything for now permission java. security. All. Permission; }; n すべての人にすべてのアクセス権を与える クライアントの起動 n java -Djava. security. policy=policy. txt Hello. Client localhost 参考文献・URL n Java. TM Remote Method Invocation (RMI) n n http: //java. sun. com/j 2 se/1. 4/ja/docs/ja/gui de/rmi/ Sun Microsystems による RMI の解説です。