how to differentiate received messages between users using smack and java?

守給你的承諾、 提交于 2019-12-10 17:14:48

问题


I am using servlets to send & receive chat messages to facebook using smack . In that user's "A" & "B" are chating with user "C". If user "C" send's message only to "A" ,that message also received by "B". How to differenciate the messages between users?

finally my problem is ,to whom the message is cmg from facebook.

By using below code to get messages:

public void processMessage(Chat chat, Message message) {

                 if ((message != null) && (message.getBody() != null)) {

                    System.out.println(chat.getParticipant() +"--"+ message.getBody());

                  }
            }

回答1:


Each Message object will contain a header and body. Header is basically a mapping of name value pairs. I would suggest to put userid in header of message. Now in you chat client you can implement message filtering based user id in header. This should resolve your issue.

Edit:

This link : http://www.quepublishing.com/articles/article.aspx?p=26270&seqNum=6 has details on usage of header.



来源:https://stackoverflow.com/questions/23440866/how-to-differentiate-received-messages-between-users-using-smack-and-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!