Can't connect to java rmi server(which is in aws) from my local machine

25 Views Asked by At

I have vpc in which I have launched my windows ec2 instance on public subnet and it has public ip and private ip address. In that windows ec2 instance I have added one small rmi server and it is running and in firewall i have given permission for rmi port 1099 and icmpv4 for connection. And also in security groups I have added protocols such as rmi-1099, icmp, tcp and udp. and also in ACLs too. When I try to connect to that rmi server from my local machine using rmi client then it is throwing error of connection request timed out. But when I launch another ec2 instance2 and add rmi client and try to connect to rmi server in another ec2 instance it is working fine with no issues. but when I try to connect from my local machine it is not working. How to resolve this pls someone guide me in this, I need to resolve this issue.

When I run my code, it throws exception error along with private ip address "10.0.0.240" of ec2 instance:

public class RMIClient {

    private UpperCaseServer server;

    public RMIClient() {}

    public void startClient() throws RemoteException, NotBoundException {
        System.setProperty("java.rmi.server.hostname","44.194.41.198");
        Registry registry = LocateRegistry.getRegistry("44.194.41.198", 1099);
        server = (UpperCaseServer)registry.lookup("Server");
    }

    public String toUpperCase(String argument) {
        String result = null;
        try {
            result = server.toUpperCase(argument);
        } catch (RemoteException e) {
            e.printStackTrace();
            throw new RuntimeException("Could not contact server");
        }
        return result;
    }
}

    java.rmi.ConnectException: Connection refused to host: 10.0.0.240; nested exception is: 
        java.net.ConnectException: Connection timed out: connect
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:623)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:131)
        at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:235)
        at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:180)
        at com.sun.proxy.$Proxy0.toUpperCase(Unknown Source)
        at returnexample.client.RMIClient.toUpperCase(RMIClient.java:25)
        at returnexample.client.RunClient.main(RunClient.java:22)
    Caused by: java.net.ConnectException: Connection timed out: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)
        at java.net.Socket.connect(Socket.java:606)
        at java.net.Socket.connect(Socket.java:555)
        at java.net.Socket.<init>(Socket.java:451)
        at java.net.Socket.<init>(Socket.java:228)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:617)
        ... 8 more
1

There are 1 best solutions below

1
Mahdi Chaaben On

Here are a few things you can check to troubleshoot and resolve the issue:

Server Availability: Ensure that the RMI server is running and accessible from the client machine. You can verify this by attempting to ping the server's IP address (44.194.41.198) from the client machine.

Firewall Configuration: Check if there's a firewall or security group setting blocking incoming connections to the RMI server on port 1099. If so, adjust the firewall rules to allow incoming connections on this port.

Network Configuration: Verify that the client machine is connected to the same network or has proper network access to reach the server. Check for any network misconfigurations or restrictions that may prevent the client from reaching the server.

Server IP Address: Ensure that the IP address (44.194.41.198) and port (1099) used to connect to the RMI server are correct and accessible from the client machine.

Hostname Configuration: Although you've set the system property "java.rmi.server.hostname" to "44.194.41.198", ensure that the RMI server is actually bound to this IP address. If the server is bound to a different IP address or hostname, adjust the property accordingly.

Server Startup Logs: Check the logs or console output of the RMI server to see if there are any errors or exceptions occurring on the server side that may be preventing it from accepting connections.