954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Rmi by Internet connection

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...

Venks
Light Poster
35 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

Firewall?

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

either that or the server process is bound to the local network address and therefore trying to call the process through its external address isn't going to get a response.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

When iam using external ip(125.17.11.232) to connect server its working fine in LAN but it gives error when iam try to run in internet connection
Exception in thread "main" java.lang.RuntimeException: java.rmi.ConnectIOExcepti
on: Exception creating connection to: 194.9.30.245 nested exception is:

In error show my server local ip 194.9.30.245 ,

coding:
Server :
Server.java

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 = 60020;
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
RemoteInterface.java

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 = 60020;

try
{
Registry registry =
LocateRegistry.getRegistry("125.17.11.232",REGISTRY_PORT);
RemoteInterface remoteReference =
(RemoteInterface) registry.lookup(REGISTRY_NAME);
System.out.println(remoteReference.getMessage());
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}

Please send me solution for this problem

Venks
Light Poster
35 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

any solution for this problem...

Venks
Light Poster
35 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

Maybe, if you were to show what the nested exception is.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

java.rmi.ConnectIOException: Exception creating connection to: 194.9.30.242; nested exception is:
java.net.NoRouteToHostException: No route to host: connect
this is my Exception

Venks
Light Poster
35 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

That is, seemingly, not a publicly available ip address (i.e. can't be reached from the internet, at all), or you are attempting it to access throught the wrong interface on your computer, and so have no network path to it.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

im using public ip in my client,what are the changes that i have to do in my program? in client or server program?

Venks
Light Poster
35 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You