Java RMI 和远程文件访问

发布于 2024-10-15 11:52:24 字数 195 浏览 2 评论 0原文

我刚刚开始学习Java的RMI,并且相信我理解这个过程,客户端发送方法请求和参数,服务器进行计算并将返回结果发回。

但是,服务器是否在本地执行该方法中的所有操作?

具体来说,如果在该方法中读取文件,我认为这是由服务器执行的是否正确?

如果是这种情况,是否有任何方法可以专门从客户端访问资源(例如客户端的 System.out?)

I'm just starting to learn Java's RMI, and believe I understand the process, client sends method requests and params, server does computation and sends return result back.

However does the server perform everything within the method locally?

Specifically, if a file is read in the method, am I correct in thinking this is performed by the server?

If this is the case is there any way for the method to specifically access resources from the client (such as the client's System.out?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝天白云 2024-10-22 11:52:24
  1. 如果本地是指在服务器(虚拟)机器上,那么答案是肯定的。
  2. 是的。
  3. 不可以,只能访问作为参数显式传递给远程方法的值。而且您只能传递可序列化的对象,而流通常则不然。

话虽如此,客户端也可以充当服务器,导出自己的远程对象,该对象可以传递给(其他)服务器,然后服务器可以使用该远程对象来回调客户端。

  1. If by locally, you mean on the server (virtual) machine, the answer is yes.
  2. Yes.
  3. No, only values explicitly passed as arguments to the remote method are accessible. And you can only pass objects which are Serializable, and streams typically aren't.

Having said that, a client can also act as a server, exporting its own remote objects, which can be passed to the (other) server, which can then use that remote object to call the client back.

忆梦 2024-10-22 11:52:24

如果我理解你的问题,我会说是的,你是对的。根据定义,(远程)方法在服务器端运行。客户端只持有一个假对象(代理或存根),它与服务器建立连接,传递参数并为您获取返回值。

想想客户端和服务器运行在不同的机器上,服务器无法知道客户端的资源,除非客户端将自己充当服务器。

问候

If I understand your question, I say yes, your'e correct. By definition the (remote)method runs on the server side. The client just holds a fake object (proxy or stub) that makes the connection to the server, passes the arguments and gets the return value for you.

Think about the client and server running in different machines, there's no way to server knows anything about the client's resources, unless the client acts itself as a server.

Regards

够钟 2024-10-22 11:52:24

您可以使用 rmiio 通过 rmi 轻松传输数据。这就是说我非常怀疑你会想用 System.out 来做到这一点。

You can use rmiio to easily stream data over rmi. that said i highly doubt you would want to do that with System.out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文