避免 XMPP 消息“无法订阅自己”
Posted
技术标签:
【中文标题】避免 XMPP 消息“无法订阅自己”【英文标题】:Avoid XMPP message "Cannot Subcribe to yourself" 【发布时间】:2014-02-21 00:04:56 【问题描述】:我有以下代码来开始两个用户之间的聊天对话:
// Create Connection.
Connection.DEBUG_ENABLED = true;
config = new ConnectionConfiguration(CHAT_SERVER);
connection = new XMPPConnection(config);
connection.connect();
connection.login(chatLogin, password);
// Create Chat Manager.
chatManager = connection.getChatManager();
// Create Chat.
chat = chatManager.createChat(friendLogin, messageListener);
// Set listener for outcoming messages.
chatManager.addChatListener(chatManagerListener);
String str_your_chat_id = Integer.toString(your_chat_id);
String str_receiver_chat_id = Integer.toString(receiver_chat_id);
// Set Subscription to receive user status
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(str_your_chat_id +"-3758@chat.quickblox.com");
connection.sendPacket(subscribe);
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo(str_receiver_chat_id +"-3758@chat.quickblox.com");
connection.sendPacket(subscribed);
subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(str_receiver_chat_id +"-3758@chat.quickblox.com");
connection.sendPacket(subscribe);
subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo(str_your_chat_id +"-3758@chat.quickblox.com");
connection.sendPacket(subscribed);
但是当它运行来自 asmack 服务器的消息时,会响应“你不能订阅自己”。
有人知道我做错了什么吗?
【问题讨论】:
【参考方案1】:这段代码有问题:
// Set Subscription to receive user status
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(str_your_chat_id +"-3758@chat.quickblox.com");
connection.sendPacket(subscribe);
您为自己订阅,但您没有
很高兴听到您想要实现的目标
【讨论】:
以上是关于避免 XMPP 消息“无法订阅自己”的主要内容,如果未能解决你的问题,请参考以下文章