Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在AWS服务器上远程运行RMI服务器客户端_Java_Amazon Web Services_Ubuntu_Amazon Ec2_Rmi - Fatal编程技术网

Java 在AWS服务器上远程运行RMI服务器客户端

Java 在AWS服务器上远程运行RMI服务器客户端,java,amazon-web-services,ubuntu,amazon-ec2,rmi,Java,Amazon Web Services,Ubuntu,Amazon Ec2,Rmi,我在AmazonAWS上打开了一个EC2Ubuntu服务器。我的问题是我不能从两台不同的机器上运行我的RMI项目。更具体地说,从Windows Netbeans运行客户端,从ubuntu服务器运行服务器。如何远程运行它们。我遵循了很多指示 我已在AWS上创建了一个安全组,并接受所有入站连接。 在服务器上本地编译rmi并运行良好。所以我想我应该为公众开放rmi端口??我试过了,但因为我在虚拟机上工作,所以可能不可能。。。我还需要像Elastic Beanstalk一样将Netbeans与我的ec2

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

我已在AWS上创建了一个安全组,并接受所有入站连接。 在服务器上本地编译rmi并运行良好。所以我想我应该为公众开放rmi端口??我试过了,但因为我在虚拟机上工作,所以可能不可能。。。我还需要像Elastic Beanstalk一样将Netbeans与我的ec2服务器绑定

在服务器端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

因此,在服务器中调用
bind()
时,您未能连接到注册表,并且您在客户端成功连接到注册表,但在那里没有找到
“Hello”
。这表明
34.xxx.xxx.xx
不是服务器的IP地址,并且由于其他原因,已经有一个注册表在那里运行。是的,我知道奇怪的想法是,当我将服务器IP更改为localhost时,运行得很好……当然是这样。为什么不呢?你需要在我的评论中提出建议。所以我修正了这个。。。事实证明,我需要将物理ip与真实ip相关联。等我的场合,我需要像这样运行服务器:java SkyCorbServer“172.31.31.94”666…:D Ip和端口