简体   繁体   English

Java RMI和远程文件访问

[英]Java RMI and remote file access

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. 我刚开始学习Java的RMI,并且相信我了解过程,客户端发送方法请求和参数,服务器执行计算并返回返回结果。

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?) 如果是这种情况,该方法是否有任何方法可以从客户端专门访问资源(例如客户端的System.out?)

  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. 并且您只能传递可Serializable对象,而通常不传递流。

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. 话虽如此,客户端也可以充当服务器,导出自己的远程对象,这些对象可以传递给(其他)服务器,然后服务器可以使用该远程对象来回调客户端。

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 问候

You can use rmiio to easily stream data over rmi. 您可以使用rmiio轻松地通过rmi传输数据。 that said i highly doubt you would want to do that with System.out. 这说我非常怀疑你会想用System.out做到这一点。

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

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