【发布时间】:2023-10-23 19:17:02
【问题描述】:
我正在为大学考试写一个愚蠢的“聊天”
我必须将 RMI 与 rmic 和 rmiregistry 一起使用(旧方法)
但我在比较远程对象时有一个奇怪的行为,例如在这段代码中:
public class Server extends UnicastRemoteObject implements ServerIFace {
[...]
private ArrayList<ClientIFace> online;
[...]
public boolean join(ClientIFace client) throws RemoteException {
synchronized (online) {
if (online.size() >= MAX_CLIENTS) {
return false;
}
this._sendBroadcast("New User: " + client.getNickname(), null);
online.add(client);
[...]
接下来我在调用客户端和在线列表元素之间进行的每次比较都失败了:
private void _sendBroadcast(String mex, ClientIFace sender)
throws RemoteException {
for (ClientIFace c : online) {
if (c != sender) {
c.recvMsg(mex);
}
}
}
"if (c != sender)" 永远不会返回 false ,但 "sender" 是客户端 加入时在线添加。
我做错了吗?
【问题讨论】:
标签: java comparison chat rmi