在AWS服务器上运行RMI服务器Client Remotly

时间:2017-05-05 15:53:54

标签: java amazon-web-services ubuntu amazon-ec2 rmi

我在amazon AWS上打开了ec2 ubuntu服务器。我的问题是我无法从2台不同的机器上运行我的RMI项目。更具体地说,从Windows Netbeans运行客户端,从ubuntu服务器运行服务器。如何远程运行它们是可能的。我遵循了很多指示。

我在AWS上创建了一个安全组,并接受所有入站连接。 在服务器上本地编译rmi并运行正常。所以我的猜测是我应该为公众设置rmi端口?我试过但是因为我在vm上工作它可能是不可能的......我还需要将Netbeans与我的ec2服务器绑定,比如Elastic Beanstalk ......

1-2分钟后,在服务器端

我收到此错误

java.rmi.ConnectException: Connection refused to host: 34.xxx.xxx.xx; nested exception is:
        java.net.ConnectException: Connection timed out (Connection timed out)
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)

服务器代码:

    private static final int port = 1099;
    private static final String hostname = "34.xxx.xxx.xx";
    private static final String bindLocation = "//" + hostname + ":" + port + "/Hello";


public static void main(String[] args) throws RemoteException {

    // RMISecurityManager security = new RMISecurityManager();
    // System.setSecurityManager(security);

System.setProperty("java.rmi.server.hostname","34.xxx.xxx.xx");
try { // special exception handler for registry creation
    LocateRegistry.createRegistry(port);
    System.out.println("java RMI registry created.");
} catch (RemoteException e) {
    // do nothing, error means registry already exists
    System.out.println("java RMI registry already exists.");
}

SkyCorpServer server = new SkyCorpServer();

try {
    Naming.bind(bindLocation, server);

    System.out.println("Addition Server is ready at:" + bindLocation);
} catch (RemoteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (Exception e) {
    System.out.println("Addition Serverfailed: " + e);
}

我也可以从我的机器上ping服务器(windows cmd)

客户代码:

String remoteHostName = "34.xxx.xxx.xx";
        int remotePort = 1099;

        String connectLocation =  "//" + remoteHostName + ":" + remotePort + "/Hello";

        System.out.println("Connecting to client at : " + connectLocation);
        look_op = (ChatInterface)Naming.lookup(connectLocation);

客户端例外:

Exception in thread "main" java.rmi.NotBoundException: Hello
    at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:209)
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)

我希望能提前感谢任何帮助,感谢提前:D

0 个答案:

没有答案
相关问题