RMI chat app
Posted on 2000-04-20
Currently I am trying to write a chat application using RMI and JDK1.2. Since I am using jdk1.2 no Skeleton is required. Anyway I have created the server which has an interface for the client consisting of 3 methods. AddClient, which the client calls and passes itself in to register with the server. The Server then adds the reference to a vector of all the clients that are registered.
PostMessage which a client calls passing in the Message that the server is supposed to distribute to other clients.
And unregister which the client calls to unregister with the server.
Anyway, the problem I am running into is that when the client calls register on the server and passes itself to the server, the client will get serialized and the server will then receive a copy of the client instead of a reference. If I want the server to get a reference should I also create a stub for the client and have it register with the registry or can I use Remote? I thought I tried remote once and it still seemed to give the server a copy of the client instead of the reference. I can't use a copy cause when the server calls a method on the client it just executes on the server machine.
Also how can I override equals in client? Since remote methods must throw RemoteException which equals does not in Object. I need to override equals cause I am storing clients in a vector and when I add a new client to a vector I would like to make sure it does not exist...ie vector.get(client).equals(newClient).