Re: [問題] RMI

看板java作者 (shooting star)時間18年前 (2006/03/18 15:56), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/5 (看更多)
※ 引述《PsMonkey (痞子軍團團長)》之銘言: : ==站內信件== : ※ 引述《NightPrince (shooting star)》之銘言: : : 問題已經被我神奇的解決掉,打擾各位真不好意思 (光速逃) : : XD : : [local save] : 1. 既然你都已經 po 兩篇了 : 何不順便把你怎麼解決的,也一起 po 一下 : 2. 你的 local save 好像還是轉信出去耶?? : 所以,賞你一個小小警告 XDXD : (不能欺騙大家阿...) 既然版主都這樣說,我就只好野人獻曝一下,順便賺點P幣 XD 一般而言,要使用RMI的話,也就是要使用遠端的方法 所以要先定義 remote interface ,而在該 interface裡面 定義 remote methods 提供給遠端之用 所以一般的作法是先寫一個 Interface 去繼承 Remote , sample code: public interface TempServer extends Remote { public ObjectName getRemoteObject() throws RemoteException; } 之後再寫一個類別實作該 interface 並且順便註冊本身此類別為遠端物件, sample code: public class TempServerImpl extends UnicastRemoteObject implements TempServer { . . . public TempServerImpl() throws RemoteException { // 因為UnicastRemoteObject建構子會丟出 RemoteException // 所以子類別就要順便接住 } public ObjectName getRemoteObject() { return ObjectName; } public void Main(String args[]) throws Exception { TempServerImpl temp = new TempServerImpl(); String serverObjectName = "rmi://localhost/serverObject"; LocateRegistry.createRegistry(1099); //啟動registry server Naming.rebind(serverObjectName, temp); // 註冊該物件為 remote } } client sample code: public class ClientGetRemoteObject { . . . public void Main(String args[]) { String remoteObject = "rmi://140.116.96.181/serverobject"; try { TempSever remoteServer = (TempServer) Naming.lookup(remoteObject); ObjectName remoteServerObject = remoteServer.getRemoteObject; } catch(ConnectException ce_ { ce.printStackTrace(); } catch(Exception ex) { ex.printStackTrack(); } } } 用法差不多是這樣,而我剛的問題是在 server 以及 client 端 的 rmi:// 那邊,都輸入 blue.iim.ncku.edu.tw ,這當然會有錯 因為要註冊成為遠端物件,該物件一定是在 server 端嘛 所以 server 端那邊的 rmi:// 只要輸入 localhost 就好 XD 非常不應該的錯誤 [逃] 其實還有很多細節我沒說,去看 API 就知道了 [遠目] -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.96.181
文章代碼(AID): #146xqgtR (java)
討論串 (同標題文章)
本文引述了以下文章的的內容:
問題
完整討論串 (本文為第 5 之 5 篇):
問題
問題
文章代碼(AID): #146xqgtR (java)