更改默认 RMI 端口 (Java)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/939111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change Default RMI Port (Java)
提问by Ivan Bosnic
How can I change the default RMI port (1099). It could be as JVM parameter or via coding, it doesn′t matter. Thanks.
如何更改默认 RMI 端口 (1099)。它可以作为 JVM 参数或通过编码,这无关紧要。谢谢。
回答by Bill the Lizard
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. Do not forget to unset your CLASSPATH environment variable.
默认情况下,注册表在端口 1099 上运行。要在不同的端口上启动注册表,请在命令行上指定端口号。不要忘记取消设置您的 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 Programsection of the tutorial. (The same applies when implementing your server.)
在您的代码中,您使用LocateRegistry.getRegistry(String host, int port)覆盖按主机名和端口定位注册表,如本教程的创建客户端程序部分所述。(这同样适用于实现您的服务器。)
回答by user207421
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. If you extend Activatable there are similarly super() overloads with a port number. You can specify the Registry's port on the command line if you use that, otherwise via LocateRegistry.createRegistry() if you use that.
您可以在导出远程对象时指定自己的端口,通过 super(port, ...) 或 exportObject(remote, port, ...) 取决于您是否扩展 UnicastRemoteObject。如果您扩展 Activatable,则有类似的 super() 重载带有端口号。如果您使用它,您可以在命令行上指定注册表的端口,否则通过 LocateRegistry.createRegistry() 如果您使用它。