1

I have an EC2 instance running in Amazon. Its public IP is 54.72.14.247 and it is currently open to all traffic.

This instance is hosting a Fibonacci server that calculates the numbers of the fibonacci sequence when requested.

The code of the server is trivial (less than 30 lines), and can be seen in the link below:

In my local computer I have a Java client that tries to access that server:

package fiboclient;

import fiboserver.IFibonacci;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class FibonacciClient {

    public static void main(String[] args) {

        System.setProperty("java.security.policy", "client.policy");
        if(args.length == 0 || !args[0].startsWith("rmi:")){
            System.err.println("Usage: java FibonacciClient rmi://host.domain.port/fibonacci number");
            return;
        }

        try{
            Object o = Naming.lookup(args[0]);
            IFibonacci calculator = (IFibonacci) o;

            for(int i = 1; i < args.length; i++){
                try{
                    BigInteger index = new BigInteger(args[i]);
                    BigInteger f = calculator.getFibonacci(index);

                    System.out.println("The " + args[i] + "th Fibonacci number is " + f);
                }catch(NumberFormatException e){
                    System.err.println(args[i] + " is not an integer.");
                }
            }
        }catch(RemoteException e){
            System.err.println("Remote object threw exception " + e);
        } catch (MalformedURLException e) {
            System.err.println(args[0] + " is not a valid RMI URL");
        } catch (NotBoundException e) {
            System.err.println("Could not find the requested remote object on the server");
        }
    }

}

Both client and server have a policy file, called server.policy and client.policy respectively. They both have the following code:

grant{
    permission java.security.AllPermission;
};

Running Locally: Having in mind the policy files are in the right places, first launch the server, and then launch the client with the following arguments: rmi://localhost:1099/fibonacci 0 1 2 3 4 5 55 155.

And everything will work out just fine.

Asking the EC2 instance server to run: First I launched my server on the Ec2 instance. Right now, that server is listening and waiting for requests.

Then in my local machine, I run the client with the arguments rmi://54.72.14.247:1099/fibonacci 0 1 2 3 4 5 55 155 and then I get no response. Like literally, nothing happens, and I have no idea why!

Am I missing something? How can I solve the problem?

JAR files:

As a convenience, and to allow you all to test case, I have compiled the JARS. When running the JARS use the java -jar jarFileName.jar command, and make sure that the policy files are in the same folder as the jar files.

EDIT

Security Group Screenshot: enter image description here

Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
  • If this is working locally why do you still have two questions about why it doesn't work locally? – user207421 Apr 08 '14 at 22:40
  • Your misunderstand the problem. The application runs well locally, but it does not work when deployed in Amazon EC2 instances using different machines. Should I edit the question and make it more clear? – Flame_Phoenix Apr 10 '14 at 13:52
  • 1
    Flame did you ever figure this out? I have the same issue except that it works fine between two EC2 instances, just not from outside AWS. – cloudsurfin May 28 '15 at 01:58

1 Answers1

1

Have you opened the port for inbound traffic? If not follow these steps. Cheers

There is more directly on amazon here.

Community
  • 1
  • 1
Michael
  • 131
  • 5
  • All traffic is enabled.You can see the screenshot I just added ! – Flame_Phoenix Apr 08 '14 at 21:43
  • Can you verify if the requests do hit the server at all? Add some logging to your server application and check the log files so that you can see if the problem really is the inbound traffic. The second step should be to verify the OS used on EC2 regarding firewall settings. Maybe you have to open the port there as well as described via the first link in my answer. – Michael Apr 09 '14 at 04:12
  • the next thing to verify is the Security Group settings: [here](http://stackoverflow.com/questions/3955910/ec2-cannot-open-port-5080-on-windows-instance?rq=1) – Michael Apr 09 '14 at 04:19
  • I allowing ALL TRAFFIC on the SecurityGroup, as I show in my screenhot. As for firewall, I killed it, so that is not a problem either. Last try is to check incoming traffic to the server, but I am not sure on how to do it :S – Flame_Phoenix Apr 09 '14 at 13:48
  • Flame, if you check the other threads for similar problems... they all mention that the port they had problems with had to be listed explicitely. Try it. It doesn't hurt to try it. For the incomung request. Simplify your server to not do any calculation but to simply write to a file. Deploy it on EC2. Execute the local client. Then check on the server if he file has been created and written to. – Michael Apr 09 '14 at 15:41