2014-09-21 205 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註冊表。

相關問題