2011-12-15 67 views
1

示例代碼:在Java空間連接查詢?

ServiceTemplate tmp1 = new ServiceTemplate(null, classes, null); 

    try { 

    /*  if(System.getSecurityManager() == null) 

      System.setSecurityManager(new RMISecurityManager());*/ 

     thisIp = InetAddress.getLocalHost(); 
     LookupLocator locator = new LookupLocator("jini://"+thisIp.getHostName().toString()); 
     ServiceRegistrar sr = locator.getRegistrar(); 
     JavaSpace space = (JavaSpace)sr.lookup(tmp1); 
     System.out.println("Success"); 

    } 

遭遇錯誤[ServiceRegistrar SR = locator.getRegistrar();] 其中規定

java.net.ConnectException: Connection refused 
at java.net.PlainSocketImpl.socketConnect(Native Method) 
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) 
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 
at java.net.Socket.connect(Socket.java:519) 
at java.net.Socket.connect(Socket.java:469) 
at java.net.Socket.<init>(Socket.java:366) 
at java.net.Socket.<init>(Socket.java:209) 
at net.jini.core.discovery.LookupLocator.getRegistrar(LookupLocator.java:328) 
at net.jini.core.discovery.LookupLocator.getRegistrar(LookupLocator.java:286) 
at MessageEntry.main(MessageEntry.java:34) 

我是新來的JavaSpace技術,請幫助我。

預先感謝您

Jeetesh.N

+0

你是否開始服務?你是怎麼做到的?來自Apache River,Blitz或Gigaspaces的來源?提供有關問題的更多信息。 – 2011-12-15 14:20:34

回答

2

ConnectException是一個很基本的錯誤,只是意味着你的Java進程不能建立一個socket連接到目標機器和端口,因爲機器WASN不接受目標端口上的連接。在這種情況下,它幾乎肯定會嘗試使用默認的JINI端口連接到您的IP地址localhost

我建議這個錯誤意味着您執行代碼時沒有在您的機器上運行的JINI服務/註冊器。