0

hi i am using this codes for rmi

RmiServer.java

import java.rmi.*;

import java.rmi.registry.*;

import java.rmi.server.*;

import java.net.*;



public class RmiServer extends java.rmi.server.UnicastRemoteObject

implements ReceiveMessageInterface

{

    int      thisPort;

    String   thisAddress;

    Registry registry;    // rmi registry for lookup the remote objects.



    // This method is called from the remote client by the RMI.

    // This is the implementation of the gReceiveMessageInterfaceh.

    public void receiveMessage(String x) throws RemoteException

    {

        System.out.println(x);

    }



    public RmiServer() throws RemoteException

    {

        try{

            // get the address of this host.

            thisAddress= (InetAddress.getLocalHost()).toString();

        }

        catch(Exception e){

            throw new RemoteException("can't get inet address.");

        }

thisPort=3232;  // this port(registryfs port)

        System.out.println("this address="+thisAddress+",port="+thisPort);

        try{

        // create the registry and bind the name and object.

        registry = LocateRegistry.createRegistry( thisPort );

            registry.rebind("rmiServer", this);

        }

        catch(RemoteException e){

        throw e;

        }

    }



    static public void main(String args[])

    {

        try{

        RmiServer s=new RmiServer();

    }

    catch (Exception e) {

           e.printStackTrace();

           System.exit(1);

    }

     }

}

RmiClient.java

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

public class RmiClient
{
    static public void main(String args[])
    {
       ReceiveMessageInterface rmiServer;
       Registry registry;
       String serverAddress=args[0];
       String serverPort=args[1];
       String text=args[2];
       System.out.println("sending "+text+" to "+serverAddress+":"+serverPort);
       try{
           // get the �gregistry�h
           registry=LocateRegistry.getRegistry(
               serverAddress,
               (new Integer(serverPort)).intValue()
           );
           // look up the remote object
           rmiServer=
              (ReceiveMessageInterface)(registry.lookup("rmiServer"));
           // call the remote method
           rmiServer.receiveMessage(text);
       }
       catch(RemoteException e){
           e.printStackTrace();
       }
       catch(NotBoundException e){
           e.printStackTrace();
       }
    }
}

ReceiveMessageInterface.java

 import java.rmi.*;

public interface ReceiveMessageInterface extends Remote

{

  public   void receiveMessage(String x) throws RemoteException;


}

This works fine normally , but when the a computer is connected to internet through mobile or it shares internet from other pc it doesn't work

I get this error.

java.net.connectexception connection timeout

when i tried to telnet it fails to connect but when i try to run this program that pc to my pc it works.

Please let me know how to solve this issue.

user3082456
  • 1
  • 1
  • 3

1 Answers1

0

Sounds like a firewall or proxy server issue.

NicholasKarl
  • 253
  • 3
  • 12
  • no i dont think its firewall issue. supoose i have installed a vm in my machine and tried to run same program it works fine when i my frnd try to connect server program running inside that vm then he is not able to connect it it shows the same error. – user3082456 Dec 10 '13 at 05:44
  • So, it connects from within the _same_ computer/subnet but doesn't connect from a _different_ computer/subnet? If that's the case, then it's a firewall issue. – NicholasKarl Dec 10 '13 at 15:30
  • i already tried by stopping the firewall in windows pc but still it cannot connect to that pc – user3082456 Dec 11 '13 at 04:51
  • There is not much I can tell you. You have to solve network problems step by step, I can't do it here for you. You know others have got it to work, so you can too: Look at **other posts** e.g., [http://stackoverflow.com/questions/5662283/java-net-connectexception-connection-timed-out-connect?rq=1]. – NicholasKarl Dec 11 '13 at 15:26