简体   繁体   English

将RMI限制为一个端口的含义

[英]Implications of restricting RMI to one port

I'd like to be able to restrict the ports used by my application to some small-as-possible known set. 我希望能够将我的应用程序使用的端口限制为一些尽可能小的已知集。 The application uses Java RMI to communicate with a remote server. 该应用程序使用Java RMI与远程服务器通信。 The registry is exported on port 1099, which is standard. 注册表在端口1099上导出,这是标准的。 However, it appears that the port used to export the various remote objects is not always consistent, though it does stay the same across multiple connections over a short period of time. 但是,看起来用于导出各种远程对象的端口并不总是一致的,尽管它在短时间内在多个连接中保持相同。 My uneducated guess is there is some sort of caching of the server sockets going on behind the scenes which causes this. 我没有受过教育的猜测是,在幕后发生的服务器套接字存在某种缓存导致这种情况。

I'd like to be able to ensure that the connection always occurs over a few well-known ports, so that users who install the client application have to open as few ports as possible in their firewall. 我希望能够确保连接总是在几个众所周知的端口上发生,因此安装客户端应用程序的用户必须在防火墙中打开尽可能少的端口。 It seems that I could do this by changing the RMISocketFactory to a custom implementation and override the createServerSocket method to always use a known port. 我似乎可以通过将RMISocketFactory更改为自定义实现并覆盖createServerSocket方法以始终使用已知端口来实现此目的。 However, this raises a few questions: 但是,这提出了一些问题:

  • How does this affect scalability? 这对可扩展性有何影响? It sounds great if I knew only one person would ever connect at a time, but wouldn't it block multiple simultaneous connections? 如果我知道一次只能连接一个人,但是它不会阻止多个同时连接,这听起来很棒吗?
  • Is it possible to bind these remote objects on the same port as the registry? 是否可以将这些远程对象与注册表绑定在同一端口上? My intuition says no, as the port would already be bound by the createRegistry call. 我的直觉说不,因为端口已经被createRegistry调用绑定了。
  • Are there other implications I am ignorant of? 还有其他我不知道的含义吗?

wouldn't it block multiple simultaneous connections? 它不会阻止多个同时连接?

No. 没有。

Is it possible to bind these remote objects on the same port as the registry? 是否可以将这些远程对象与注册表绑定在同一端口上? My intuition says no, as the port would already be bound by the createRegistry() call. 我的直觉说不,因为端口已经被createRegistry()调用绑定了。

Yes, as long as you start the registry in the same JVM, via LocateRegistry.createRegistry() , and as long as any server socket factories involved are equal() . 是的,只要您通过LocateRegistry.createRegistry()在同一个JVM中启动注册表,并且只要涉及的任何服务器套接字工厂都equal()

Are there other implications I am ignorant of? 还有其他我不知道的含义吗?

There are no implications at all. 根本没有任何影响。 RMI does port sharing between remote objects with null or equal server socket factories, and TCP does port sharing between multiple connections to the same port. RMI使用空或相等的服务器套接字工厂在远程对象之间进行端口共享,并且TCP在到同一端口的多个连接之间进行端口共享。

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

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