繁体   English   中英

Java RMI概念

[英]java rmi concept

我正在尝试实现一个简单的聊天应用程序,该应用程序通过中央服务器将客户端与其他客户端连接,以便他们可以交换消息和文件。 我还需要实现一个通知框架。 例如,如果用户成功签名,或者用户的好友登录,他都会收到通知。 现在在RMI世界中,这是如何实现的? 我当时在考虑有一个远程对象“连接类”,客户端从中调用诸如“登录”,“断开连接”之类的方法……对于通知框架类,它们也必须是远程的吗? 还是可以躺在服务器上? 谢谢

远程系统之间的事件消息传递有些棘手。 这是必须发生的事情:

  • 客户端必须对服务器端触发的事件感兴趣。 要注册,客户端必须可远程用于事件源对象。

  • 为了能够注册,客户端必须找到开始的服务器,因此服务器对象必须可远程用于客户端。

ck,对不对? 这是实现远程事件处理的简单模式 几周前,我开始了一个沿着这条路前进的教程-就在这里,我希望在本周末之前向其中添加一些内容。 las,租金的需求已受到干扰,我无法按照自己的意愿尽快增加。 但是,如果您迫不及待,那就是关键:双方都必须远程可用,以便消息传递系统正常工作。

该服务器以及客户端必须是远程对象。

让所有客户端实现远程接口。

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();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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