RMI多个客户端 - 每个客户端一个服务器对象 [英] RMI multiple clients - one server object for each of them

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

问题描述

我正在使用RMI编写加密系统原型。

I am writing a prototype of cryptographic system using RMI.

我遇到了问题,因为当我启动两个客户端时,他们得到了一个客户的响应来自OneTimePad类的服务器。

I have a problem, because when I launch two clients, they got a response from one object in the server from OneTimePad class.

因此客户端A重新获得为客户端b保留的密钥,因为特定算法,这种情况不会发生。

So client A recives key that was reserved for client b, because of specific algorithm, this situation could not happen.

服务器只向客户端发送E和N变量(如在RSA中),因此我无法序列化OneTimePad对象并通过网络发送(因为它将包含所有密钥)。

Server send to the clients only E and N variable (like in RSA) so i can't serialize OneTimePad object and send it through the network (because it will have all keys in it).

如何为每个客户端创建OneTimePad类的一个对象?

How can I make for each client one object of OneTimePad class?

推荐答案

我在2001年的书中称之为远程会话模式。 Registry中的远程对象是一种只导出 login()方法的登录服务器。 login()方法,如果成功,则每次调用返回一个新的远程对象,基本上是每个客户端的远程会话对象。此会话对象可以导出一个 logout()方法,该方法不会导出自身,并且还可以实现 Unreferenced,这样 unreferenced()方法也会导致自身失效(或者您可以依赖DGC,无论如何都要使用相同的东西:使用 Unreferenced 给你一个记录它的机会)。此远程会话对象导出登录客户端应有权访问的所有远程方法,并且因为它是每个客户端,它可以保持客户端状态,因此它是一个会话。

I called this the Remote Session pattern in my 2001 book. The remote object in the Registry is a kind of login server exporting only a login() method. The login() method, if successful, returns a new remote object per call, which is basically a per-client remote session object. This session object can export a logout() method, which unexports itself, and it can also implement Unreferenced, such that the unreferenced() method also unexports itself (or you can rely on DGC which des the same thing anyway: using Unreferenced gives you a chance to log it). This remote session object exports all the remote methods that a logged in client should have access to, and because it is per-client it can hold client state, hence it is a session.

public interface RemoteLogin extends Remote
{
    RemoteSession login() throws RemoteException;
}

public interface RemoteSession extends Remote
{
    void logout() throws RemoteException;
    void myMethod(...) throws RemoteException; // whatever you need
}

public class RemoteLoginImpl extends UnicastRemoteObject implements RemoteLogin
{
  // ...
  public RemoteSession login()
  {
    // ...
    return new RemoteSessionImpl(); // whatever arguments you need
  }
}

public class RemoteSessionImpl extends UnicastRemoteObject implements RemoteSession, Unreferenced
{
  // ...
}

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

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