RMI multiple clients - one server object for each of them

走远了吗. 提交于 2019-11-27 06:29:49

问题


I am writing a prototype of cryptographic system using RMI.

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

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

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).

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


回答1:


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
{
  // ...
}


来源:https://stackoverflow.com/questions/15912558/rmi-multiple-clients-one-server-object-for-each-of-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!