我正在制作web应用程序聊天室,我的问题是,如果有两个房间,第一个房间名为"Funny“,只有一个用户"liam”,第二个房间"Happy“,只有一个用户" jack ",现在如果jack在房间"Happy”中发送消息,它会一直到达两个房间"Happy“和"Funny”,我如何才能阻止它并使消息到达预期的房间。
private void doNotify(String author, String message, Session skip) throws IOException{
for (Entry<Session,ChatUser> user : chatUsers.entrySet()){
Session session = user.getKey();
if (!session.equals(skip) && session.isOpen()){
session.getBasicRemote().sendText((author != null ?
//Message Model
"<li class='media'><div class='media-left'><a href='#'><img src='' class='media-object' alt='"+author
+"'/>" +" </a></div><div class='media-body'><h4 class='media-heading'>"+author+
"<small><i>"+"("+new Date()+")</i>" : "")+
"</h4><p>"+message
+"<br><button id='Reply' type='button' ng-click='ReplayMessage('"+author+"')'>"
+"Reply</button><button id='OpenBtn' type='button' ng-click=''>Open</button></br></div>");
}
}
}发布于 2017-03-03 15:25:29
检查用户的房间,并将其存储在服务器上。在sendText中,为房间添加验证。
https://stackoverflow.com/questions/42572781
复制相似问题