Java RMI - 使客户端成为服务器 [英] Java RMI - Making the client a server

查看:179
本文介绍了Java RMI - 使客户端成为服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想在我的RMI应用程序中启用双向通信(即,允许服务器调用客户端上的方法,以及客户端调用服务器上的方法)是最简单的方法客户端进入远程类吗?



此外,如果我打算将我的客户端的实例作为方法参数传递到服务器,我认为没有需要添加'客户端类'到rmiregistry?



还有一个最后一个问题,我所有的类仍然需要在同一个地方编译? IE可以在两个完全独立的机器上编译服务器和客户端,并期望它们能正常通信?



* EDIT ** 还有一个问题,我的问题引用我的客户端接口(IClient):它有一个arraylist(所以我有 ArrayList< IClient> )存储客户端的新实例,以便服务器可以跟踪注册的客户端。当我尝试在不同的机器上编译服务器时,它抱怨它不能找到IClient - 显然,因为IClient是在客户端机器上。

解决方案

您在所有假设中都是正确的。



您不必将远程可调用的客户端类添加到rmi注册表中,但您仍然必须导出它们。



编译是,他们必须使用相同的编译器设置(至少那些影响RMI存根生成)的相同版本的Java。


If i want to enable 'two way' communication in my RMI Application (That is, allow the server to invoke methods on the client, as well as the client to invoke methods on the server), is the simplest way to make the client into a Remote class as well?

Also if i intend to pass instances of my client to server as a method parameter, am i correct in thinking that there is no need to add the 'client class' to the rmiregistry?

And one final question, do all of my classes still need to be compiled in the same place? I.E can i compile server and client on two entirely independent machines and expect them to communicate properly?

* EDIT **

One more question, my question makes reference to my client interface (IClient): it has an arraylist (so i have ArrayList<IClient>) to store new instances of the client so the server can keep track of registered clients. When i attempt to compile the server on a different machine, it complains that it cant find IClient - obviously, as IClient is on the client machine. How do i get around this?

解决方案

You're right in all your assumptions.

You don't have to add your remotely callable client classes to the rmi registry but you still have to export them.

The only caveat with the compilation is that they have to be done with the same version of java with the same compiler settings (at least those affecting RMI stub generation).

这篇关于Java RMI - 使客户端成为服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆