简体   繁体   中英

java rmi concept

I am trying to implement a simple chat application that connects clients through a central server, with other client so they can exchange messages and files. I also need to implement a notification framework. for example, if a user signs successfully, or if a buddy of him signs in he get a notification. Now in the RMI world how is this implemented? I was thinking of having a remote object "connection class" that the clients call methods from it like "login in", "disconnect" etc... And as for the notification framework classes do they have to be remote too? or can they lie in the server? thanks

Event messaging between remote systems is a bit tricky. Here's what has to happen:

  • The client must register interest in the events fired on the server side. To register, the client must be remotely available to the event source object.

  • In order to be able the register, the client must find the server to begin with, so the server object must be remotely available to the client.

Ick, right? And that's the simple pattern for implementing remote event handling. A few weeks ago I started a tutorial that was heade down this path -- it's right here, and I'm hoping to add something to it before the end of the week. Alas, the need to make the rent has interfered and I'm not able to add to it as quickly as I'd like. If you can't wait, however, that's the key: both sides have to be remotely available for the messaging system to work.

that server as well as the client must be remote objects.

Let all clients implement a Remote interface.

RemoteClientIfc extends Remote {
    void inform();
}

//have a remote method register() on the *Server* object which accepts RemoteClientIfc.
//c'd be something like this...
register(RemoteClientIfc client){
    arrayListofClients.add(client);
}

//So client will do a look up on the remote server object and register itself.
remoteObj.register(clientInstance);

//In the remote server you
//can probably have another method to send notifications to the client.
//Run through the ArrayList and call 
//inform() on each of them.
//Thus the client will receive notification.
tellClients(){
    Iterator i = ....
    while (i.hasNext()){
        ((RemoteClientIfc).i.next()).inform();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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