2015-10-18 73 views
0

上运行RMI注册我学习RMI概念,已经建立了一个简单的程序,从采取基准喷墨头的第一个Java。所有在我第一次通过命令提示符运行代码时都很好。不能在我的系统

下一次我跑了代码的命令:

rmiregistry 

花了太长时间来加载和什么都没有发生。

我甚至尝试在这个线程解决方案,但没有happend。

need help to run RMI Registry

还当我跑我的服务器和客户端文件,我得到这个错误:

Exception: java.rmi.ConnectException: Connection refused to host: 192.168.1.105; nested exception is: 
    java.net.ConnectException: Connection refused: connect 

我的源代码:

myremote.java

import java.rmi.*; 

public interface myremote extends Remote 
{ 
    public String sayhello() throws RemoteException; 
} 

Server.java

import java.rmi.*; 
import java.rmi.server.*; 

public class Server extends UnicastRemoteObject implements myremote 
{ 
    public Server() throws RemoteException{} 

    public String sayhello() 
    { 
     return("Server says hi"); 
    } 
    public static void main(String args[]) 
    { 
     try 
     { 
      myremote S = new Server(); 
      Naming.rebind("remotehello",S); 
     } 
     catch(Exception E) 
     { 
      System.out.println("Exception: "+E); 

     } 

    } 
} 

client.java

import java.rmi.*; 
public class client 
{ 
    public static void main(String[] args) 
    { 
      client c = new client(); 
      c.go(); 
    } 

    public void go() 
    { 
     try 
     { 
      myremote S=(myremote) Naming.lookup("rmi://127.0.0.1/remotehello"); 

      System.out.println("Output:"+S.sayhello()); 
     } 
     catch(Exception E) 
     { 
      System.out.println("Exception: "+ E); 
     } 
    } 
} 
+0

你的意思是什么由“花了太长时间来加载”?而'没有发生'?而不是什么? – EJP

回答

0

Can't run RMI registry on my system

你没有提供这方面的证据。

took too long to load

我不知道这是什么意思。证据?

nothing happened.

什么都不应该发生。 RMI注册表不会打印任何内容。它只是坐在那里。

运行它,然后再试一次。你会感到惊讶。

+0

我也跑了好几遍。但是我的服务器和客户端文件会产生上述异常。 –

+0

那只能说明你还没有开始注册表。 – EJP