开发者

java rmi concept

开发者 https://www.devze.com 2023-02-25 04:04 出处:网络
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 fr

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 开发者_C百科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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号