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: