简体   繁体   English

更改默认RMI端口(Java)

[英]Change Default RMI Port (Java)

How can I change the default RMI port (1099). 如何更改默认RMI端口(1099)。 It could be as JVM parameter or via coding, it doesn´t matter. 它可以作为JVM参数或通过编码,无关紧要。 Thanks. 谢谢。

You can specify it on the command line. 您可以在命令行中指定它。 From the RMI Tutorial : RMI教程

By default, the registry runs on port 1099. To start the registry on a different port, specify the port number on the command line. 默认情况下,注册表在端口1099上运行。要在其他端口上启动注册表,请在命令行上指定端口号。 Do not forget to unset your CLASSPATH environment variable. 不要忘记取消设置CLASSPATH环境变量。

Microsoft Windows:

start rmiregistry 2001

Solaris OS or Linux:

rmiregistry 2001 &

In your code you use the LocateRegistry.getRegistry(String host, int port) override to locate the registry by hostname and port, as explained in the Creating a Client Program section of the tutorial. 在您的代码中,您使用LocateRegistry.getRegistry(String host,int port)覆盖来按主机名和端口定位注册表,如本教程的“ 创建客户端程序”部分中所述。 (The same applies when implementing your server.) (实现服务器时也是如此。)

You can specify your own port when exporting your remote object, either via super(port, ...) or exportObject(remote, port, ...) depending on whether you do or don't extend UnicastRemoteObject. 导出远程对象时,可以通过super(port,...)或exportObject(remote,port,...)指定自己的端口,具体取决于是否扩展UnicastRemoteObject。 If you extend Activatable there are similarly super() overloads with a port number. 如果扩展Activatable,则会有类似的带有端口号的super()重载。 You can specify the Registry's port on the command line if you use that, otherwise via LocateRegistry.createRegistry() if you use that. 如果使用,可以在命令行上指定注册表的端口,否则通过LocateRegistry.createRegistry()使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM