Hai Friends
Iam using RMI concept for my project, i want to connect client and server by using internet connection , but its working fine on LAN connection, it gives following Exception
java.lang.RuntimeException: java.rmi.ConnectException: Connection refused to hos
t: 125.17.11.229; nested exception is:
java.net.ConnectException: Connection refused: connect
at Client.init(Client.java:23)
at sun.applet.AppletPanel.run(AppletPanel.java:417)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.rmi.ConnectException: Connection refused to host: 125.17.11.229; n
ested exception 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
)
125.17.11.229 is my internet IP
my code
Server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class Server implements RemoteInterface
{
public String getMessage()
{
return "Hello World";
}
public static void main(String args[])
{
try
{
String REGISTRY_NAME = "RMI_Example";
int REGISTRY_PORT = 3032;
Registry registry = LocateRegistry.getRegistry(REGISTRY_PORT);
RemoteInterface remoteReference =
(RemoteInterface) UnicastRemoteObject.exportObject(new Server());
registry.rebind(REGISTRY_NAME, remoteReference);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
Interface:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteInterface extends Remote
{
String getMessage() throws RemoteException;
}
client:import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.swing.JApplet;
import javax.swing.JLabel;
import java.rmi.*;
public class ClientApplet
{
public static void main(String arg[])
{
String REGISTRY_NAME = "RMI_Example";
int REGISTRY_PORT = 3032;
try
{
Registry registry =
LocateRegistry.getRegistry("125.17.11.229",REGISTRY_PORT);
RemoteInterface remoteReference =
(RemoteInterface) registry.lookup(REGISTRY_NAME);
System.out.println(remoteReference.getMessage());
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
plz help me for this problem...