javarmi客户机如何使用域名连接到javarmi服务器

rsl1atfo  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(323)

**结束。**此问题不符合堆栈溢出准则。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

上个月关门了。
改进这个问题
我正在使用javarmi编写一个应用程序。我已经创建了客户端和服务器。但是,我只使用localhost。我想能够使用一个域名为客户端联系服务器。我已经注册了一个域名:hotel.ddns.net。我希望能够保持它在个人网络中,而不是与端口转发等。客户端和服务器位于不同的计算机上。我一直在寻找解决方案,但这些与我的问题没有直接关系。你们能帮帮我吗,因为我还是新手?
这是我的客户代码:

package Hotel_;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java_rmi.java_rmi_interface;

public class ClientRMI {

    public java_rmi_interface connectToServer() throws NotBoundException{
    try{
        Registry myregistry = LocateRegistry.getRegistry("127.0.0.1",1099);
        java_rmi_interface myinterface = (java_rmi_interface)myregistry.lookup("bookingServer");
        System.out.println("client reaaaaaaady");

    return myinterface;

    }catch(RemoteException e){
        e.printStackTrace();
    }

    return null;
    }
}

这是我的服务器代码

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;

public class ServerRMI {
    public static void main(String[] args){
    try{
        //Timer timer = new Timer();
        //timer.deletefunc();
        Registry myregitry = LocateRegistry.createRegistry(1099);//create a registry that can be 
        accessed on this port
        QueryCentre qs = new QueryCentre();//an instance of QueryCenter where remote methods are 
    found
        Naming.rebind("bookingServer", qs);//naming the server and passing the class where remote 
     methods are found
        System.out.println("server ready and waitiiiinnnggg!!!!!");
    }catch(RemoteException | MalformedURLException e){
        e.printStackTrace();
    }
    }  
}
xriantvc

xriantvc1#

如果您完全在具有专用ip地址(即192.168.x.x)的个人网络中工作,那么ddns将不会为您做任何事情。它仅用于外部可路由地址。
从最复杂到最不复杂,您有几个选择:
在局域网内运行dns服务器,将主机名Map到本地ip地址。这是一项不平凡的工作,但如果您想了解更多有关dns的信息,可能会很有趣。
在/etc/hosts中添加行以将名称Map到本地ip地址。您必须确保每个希望与服务器通信的主机在其/etc/hosts副本中都有Map。
不用主机名,只使用ip地址。
我强烈推荐#3用于您的简单设置。

相关问题