Connection Refused Exception, When trying to implement RMI between 2 ip's

I am trying to implement a simple RMI HelloWorld Program between 2 systems with different IP address, one as server and other as Client, the code is as follows:

Server ( RemoteObject.java)

import java.rmi.Naming;

import java.rmi.RMISecurityManager;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;

publicclass RemoteObjectextends UnicastRemoteObjectimplements IRemoteInterface

{

String strName;

public RemoteObject(String strName)throws RemoteException

{

super();

this.strName = strName;

}

public String getMessage(String strMsg)throws RemoteException

{

String strReturn ="My Name is "+strName+", Thanks for your message "+strMsg;

System.out.println("The Return String is "+strReturn);

return strReturn;

}

publicstaticvoid main(String args[])

{

System.setSecurityManager(new RMISecurityManager());

try

{

String myName ="172.21.30.24";//"ServerTest";

RemoteObject theServer =new RemoteObject(myName);

Naming.rebind(myName,theServer);

System.out.println("Ready to continue");

}

catch(Exception e)

{

System.out.println("An Exception occured while creating server"+e);

}

}

}

Client ( RemoteClient.java)

import java.rmi.Naming;

import java.rmi.RMISecurityManager;

publicclass RemoteClient{

publicstaticvoid main(String[] args)

{

System.setSecurityManager(new RMISecurityManager());

try

{

IRemoteInterface server = (IRemoteInterface)Naming.lookup("172.21.30.20");

String strServerString = server.getMessage("Hello There from client");

System.out.println("The server says "+strServerString);

}

catch(Exception e)

{

System.out.println("Exception in RemoteClient"+e);

e.printStackTrace();

}

}

}

Interface (IRemoteInterface.java)

import java.rmi.Remote;

import java.rmi.RemoteException;

publicinterface IRemoteInterfaceextends Remote

{

String getMessage(String strMsg)throws RemoteException;

}

Exception it is giving :

Exception in RemoteClientjava.rmi.ConnectException: Connection refused to host:

172.21.30.24; nested exception is:

java.net.ConnectException: Connection refused: connect

java.rmi.ConnectException: Connection refused to host: 172.21.30.24; nested exce

ption is:

java.net.ConnectException: Connection refused: connect

at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)

at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)

at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)

at sun.rmi.server.UnicastRef.newCall(Unknown Source)

at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)

at java.rmi.Naming.lookup(Unknown Source)

at RemoteClient.main(RemoteClient.java:25)

Caused by: java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(Unknown Source)

at java.net.PlainSocketImpl.connectToAddress(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.<init>(Unknown Source)

at java.net.Socket.<init>(Unknown Source)

at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S

ource)

at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S

ource)

... 7 more

81-265-0044-1

start rmiregistry (optional port :default port 1099 )

The policy files in both the systems are as below:

// Standard extensions get all permissions by default

grant codeBase"file:${{java.ext.dirs}}/*"{

permission java.security.AllPermission;

};

// default permissions granted to all domains

grant{

permission java.lang.RuntimePermission"stopThread";

permission java.net.SocketPermission"*:1024-65535","listen,accept,connect";

permission java.util.PropertyPermission"*","read";

permission java.io.FilePermission"*","read,write";

permission java.lang.RuntimePermission"*";

};

Any help would be greatly appreciated.....

[7072 byte] By [Funnya] at [2007-10-3 5:16:15]
# 1
Put the "/ServerTest" back into the rebind string and the lookup string.
ejpa at 2007-7-14 23:22:53 > top of Java-index,Core,Core APIs...