Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RMI with multiple nic

18 views
Skip to first unread message

Pama

unread,
Mar 19, 2004, 5:48:54 AM3/19/04
to
Hello,
I'm writing a simple RMI application,
and it works well when runs on machines configured with single ip
address.
Now I have two computers (I call them A and B), and everyone has two
nic with these ip address:

A -> 129.178.1.13 - 129.178.3.13 (netmask ffffff00)
B -> 129.178.1.103 - 129.178.3.103 (netmask ffffff00)

these computers are connected only on lan 129.178.3.x (for example on
B "ping 129.178.1.13" fails).
If RMIServer runs on computer A and RMIClient on computer B,
first RMIClient gets a remote reference to an object on RMIServer,
but if RMIClient invokes a method of remote object exceptions are
thrown.


A> java EchoRMIServer 1500 //When I run RMIServer on A

LocalHost 129.178.1.13
Listening on port 1500

**************************

B> java EchoRMIClient 129.178.3.13 1500 //When I run RMIClient on B

LocalHost 129.178.1.103
I'm connected to Server 129.178.3.13 on port 1500

Write a message [q to exit]: Hello
java.rmi.ConnectException: Connection refused to host: 129.178.1.13;
nested exception is:
java.net.ConnectException: Connection timed out
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:567)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:101)
at EchoRMIServer_Stub.getEcho(Unknown Source)
at EchoRMIClient.main(EchoRMIClient.java:22)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.<init>(Socket.java:290)
at java.net.Socket.<init>(Socket.java:118)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:122)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
... 5 more

******** END ********************

I see that for B localhost is 129.178.1.103 and exception is
"Connection refused to host: 129.178.1.13",
I think RMI try to create a socket between 129.178.1.13 and
129.178.3.103. My question is:
how can I create socket between 129.178.3.13 and 129.178.3.103 ?

Thanks in advance for your help!

Paolo

***************************

Here is code:

/* EchoInterface.java */

import java.rmi.*;

public interface EchoInterface extends Remote{
public String getEcho(String echo) throws RemoteException,
java.net.UnknownHostException;
}

*******************************
/* EchoRMIServer.java */

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


public class EchoRMIServer extends UnicastRemoteObject implements
EchoInterface {

private int cont;
private int port;
String ip;

public EchoRMIServer (int portNumber) throws RemoteException,
java.net.UnknownHostException {
super();
port = portNumber;


}
public String getEcho(String echo) throws RemoteException,
java.net.UnknownHostException{
String risposta = new String("I'm Server " +
InetAddress.getLocalHost().getHostAddress() + " and answer: " + echo);
System.out.println("Remote call to Server number " + ++cont + " -
Listening on port " + port);
return risposta;
}
public static void main(String[] args){
if(args.length<1){
System.out.println("java EchoRMIServer <port>");
System.exit(1);
}
try{
System.out.println("\nLocalHost " +
InetAddress.getLocalHost().getHostAddress());
Integer integerPort = new Integer(args[0]);
int porta = integerPort.intValue();
EchoRMIServer serverRMI = new EchoRMIServer(porta);
Registry rmiRegistry =
LocateRegistry.createRegistry(serverRMI.port);
rmiRegistry.rebind("EchoService", serverRMI);
System.out.println("Listening on port " + serverRMI.port + "\n");
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
}
}

*************************************
/* EchoRMIClient.java */

import java.rmi.*;
import java.io.*;
import java.net.*;

public class EchoRMIClient{
public static void main(String[] args){

if(args.length<2){
System.out.println("java EchoRMIClient <host> <port>");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new
InputStreamReader(System.in));
try{
System.out.println("\nLocalHost " +
InetAddress.getLocalHost().getHostAddress());
EchoInterface serverRMI = (EchoInterface) Naming.lookup("rmi://" +
args[0] + ":" + args[1] + "/EchoService");
System.out.println("I'm connected to Server " + args[0] + " on port
" + args[1]);
String message, echo;
System.out.print("\nWrite a message [q to exit]: ");
message = stdIn.readLine();
while(!message.equalsIgnoreCase("q")){

echo = serverRMI.getEcho(message);
System.out.println(echo);
System.out.print("Write a message [q to exit]: ");
message = stdIn.readLine();

}
}
catch(Exception e){
e.printStackTrace();
System.exit(1);
}
}
}

0 new messages