2013-01-10 2 views
0

이것은 처음으로 RMI를 사용하고 있습니다. 기본적으로 다음 RMI 예제를 로컬 PC에서 실행하지만 두 대의 Linux 머신을 통해 실행하지는 않습니다.rmi - ConnectException

서버 인터페이스 :

public interface PowerService extends Remote{ 
public BigInteger square (int number) 
    throws RemoteException; 

public BigInteger power (int num1, int num2) 
    throws RemoteException; 
} 

서버 : 클라이언트

public class PowerServiceServer extends UnicastRemoteObject implements 
    PowerService { 

public PowerServiceServer() throws RemoteException { 
    super(); 
} 

public BigInteger square(int number) throws RemoteException { 
    imp ..... 
    return (bi); 
} 

public BigInteger power(int num1, int num2) throws RemoteException { 
    imp ..... 
    return bi; 
} 

public static void main(String[] args) throws Exception { 

    PowerServiceServer svr = new PowerServiceServer(); 
    // ... and bind it with the RMI Registry 
    Naming.bind("PowerService", svr); 
    System.out.println("Service bound...."); 
} 
} 

:

public class PowerServiceClient { 
public static void main(String args[]) throws Exception { 
    // Call registry for PowerService 
    PowerService service = (PowerService) Naming.lookup("rmi://" + args[0] 
      + "/PowerService"); 
    DataInputStream din = new DataInputStream(System.in); 
    for (;;) { 
     System.out.println("1 - Calculate square"); 
     System.out.println("2 - Calculate power"); 
     System.out.println("3 - Exit"); 
     System.out.println(); 
     System.out.print("Choice : "); 

     String line = din.readLine(); 
     Integer choice = new Integer(line); 

     int value = choice.intValue(); 

     switch (value) { 
     case 1: 
      // Call remote method 
      .................... 
      break; 
     case 2: 
      // Call remote method 
      .................... 
      break; 
     case 3: 
      System.exit(0); 
     default: 
      System.out.println("Invalid option"); 
      break; 
     } 
    } 
} 

클라이언트 인터페이스가 서버와 같은 동일

이 무엇인가? 서버 측에서

1) 내가 스텁

2) 실행 rmiregisrty

3) 서버

실행 4) 나는 복사를 생성 : 나는 RMI 예제를 실행하기 위해 한 같은 패키지

5) 클라이언트를 실행 한 후 클라이언트

을 실행에에서 클라이언트 측에 서버 측에서 스텁 나는 다음과 같은 오류가 발생했습니다 메시지 :

스레드 "main"의 예외 java.rmi.ConnectException : 호스트에서 거부 된 연결 : 127.0.0.1; 중첩 예외가 : java.net.ConnectException : 연결이 거부되었습니다 at sun.rmi.transport.tcp.TCPEndpoint.newSocket (TCPEndpoint.java:601) at sun.rmi.transport.tcp.TCPChannel.createConnection (TCPChannel.java : 198) at sun.rmi.transport.tcp.TCPChannel.newConnection (TCPChannel.java:184) at sun.rmi.server.UnicastRef.invoke (UnicastRef.java:110) at compute.PowerServiceServer_Stub.square (알 수 없음 출처)

방화벽으로 인해 연결할 수 없거나 뭔가 잘못하고있을 가능성이 있습니까 ??

감사

+0

127.0.0.1 당신이 연결할 것으로 예상되는 IP 주소입니까? 즉, 클라이언트가 서버와 동일한 호스트에서 실행되고 있습니까? NB 원격 메소드 * 구현은 컴파일러가 주장하지 않는 한'RemoteException'을 던지는 것으로 선언 할 필요가 없습니다. 컴파일러는 자신의 원격 메소드를 호출하는 경우에만 발생하며 이는 드문 경우입니다. – EJP

+0

아니요 ip 127.0.0.1은 클라이언트가 다른 컴퓨터 (IP)에있는 것을보고 기다려야하는 것이 아닙니다 – angus

답변

0

이는 RMI 자주 묻는 질문에 java.rmi.server.hostname. 참조 항목 A.1에 의해 해결 된 문제입니다. 그/etc/hosts 잘못된 구성을 수정하거나 원격 개체를 내보내기 전에 서버 JVM의 시스템 등록 정보 java.rmi.server.hostname을 서버의 올바른 IP 주소로 설정해야합니다.

+0

대단히 감사합니다. – angus