2014-09-21 177 views
0

我正在开发一个基于java和rmi的简单的基于服务器的计算程序。但是,服务器不会使用以下例外进行初始化。Java RMI连接拒绝主机异常

Initializing Server 
Remote Server Error:Connection refused to host: 192.168.1.3; nested exception is: 
    java.net.ConnectException: Connection refused: connect 

我已关闭我的微软防火墙。之后,问题仍然存在。这里是我正在运行的代码:

import java.rmi.*; 
    import java.rmi.Naming.*; 
    import java.rmi.server.*; 
    import java.rmi.registry.*; 
    import java.net.*; 
    import java.util.*; 

    interface mathInterface extends Remote 
    { 
    public int add(int a,int b) throws RemoteException; 
    public int subt(int a,int b) throws RemoteException; 
    public int mult(int a,int b) throws RemoteException; 
    public int div(int a,int b) throws RemoteException; 
    } 

    public class mathServer extends UnicastRemoteObject implements mathInterface 
    { 
       public mathServer() throws RemoteException 
       { 
           System.out.println("Initializing Server"); 
    } 
    public int add(int a,int b) 
    { 
           return(a+b); 
       } 
       public int subt(int a,int b) 
        { 
               return(a-b); 
       } 
       public int mult(int a,int b) 
        { 
               return(a*b); 
       } 
       public int div(int a,int b) 
        { 
               return(a/b); 
       } 
       public static void main(String args[]) 
       { 
           try 
           { 
           mathServer ms=new mathServer(); 
           java.rmi.Naming.rebind("MathServ",ms); 
           System.out.println("Server Ready"); 
        } 
        catch(RemoteException RE) 
        { 
               System.out.println("Remote Server Error:"+ RE.getMessage()); 
               System.exit(0); 
           } 
           catch(MalformedURLException ME) 
           { 
               System.out.println("Invalid URL!!"); 
           } 
       } 
} 

请帮我解决这个问题。

回答

0

您还没有启动RMI注册表。