127.0.0.2 address appearing out of nowhere!
I made a trivial console-based chat application to learn RMI and the callback feature. It works when I run it at the same computer, but when I start the server part on the linux box and then try to connect to it with the client part (by specifying the server address 192.168.1.103 as argument) from windows i get this exception:
java.rmi.ConnectException: Connection refused to host: 127.0.0.2; nested excepti
on is:
java.net.ConnectException: Connection refused: connect
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 callback.ServerImpl_Stub.addClient(Unknown Source)
at callback.ClientMain.main(ClientMain.java:43)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:179)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
... 5 more
...so where does this 127.0.0.2 address come from?! I can ping the machines from each other and the firewall on the linux is off. Java on both machines is java SE6
here are my interfaces:
publicinterface ServerIntextends Remote{
publicvoid addClient(ClientInt client)throws RemoteException;
publicvoid removeClient(ClientInt client)throws RemoteException;
publicvoid publish(String clientID, String msg)throws RemoteException;
}
publicinterface ClientIntextends Remote{
publicvoid notify(String msg)throws RemoteException;
public String getID()throws RemoteException;
}
and here are the main classes that manages objects which implement my remote interfaces (ClientImpl and ServerImpl):
publicclass ServerMain{
/** Creates a new instance of ServerMain */
public ServerMain(){
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args){
ServerImpl server =new ServerImpl();
try{
LocateRegistry.createRegistry(1099);
ServerInt stub = (ServerInt)UnicastRemoteObject.exportObject(server, 0);
Registry registry = LocateRegistry.getRegistry();
registry.bind("MyServer", stub);
System.err.println("Server ready");
}catch (Exception ex){
ex.printStackTrace();
}
}
}
publicclass ClientMain{
/** Creates a new instance of ClientMain */
public ClientMain(){
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args){
String host = args[0];
String clientName = args[1];
ClientImpl client =new ClientImpl(clientName);
try{
Registry registry = LocateRegistry.getRegistry(host);
ServerInt localStub = (ServerInt) registry.lookup("MyServer");
UnicastRemoteObject.exportObject(client,0);
localStub.addClient(client);
BufferedReader keyboard =new BufferedReader(new InputStreamReader(System.in));
String userInput ="";
while(!userInput.equals("quit")){
userInput = keyboard.readLine();
localStub.publish(clientName, userInput);
}
localStub.removeClient(client);
UnicastRemoteObject.unexportObject(client,false);
System.out.println("Connection to Server closed");
}catch (Exception ex){
ex.printStackTrace();
}
}
}
EDIT: the server is started with java -classpath D:/Java/ -Djava.rmi.server.codebase=file:D:/Java/ callback.ServerMain
and to connect with a client:
java -classpath D:/Java/ callback.ClientMain serverAddr myNick
Message was edited by:
dadox01

