[英]XMPP 1 to 1 chat query?
I am developing a chat project using Openfire.我正在使用 Openfire 开发一个聊天项目。
I have done with group chatting.我已经完成了群聊。
But confusion is in 1 to 1 chat.但困惑在于一对一的聊天。
I am using:我在用:
<message from='user2@server/user2' to='user1@server/user1' type='chat'>
<body>TEST< /body>
</message>
but it does not send it.但它不发送。
Thanks in advance.提前致谢。
- (AppDelegate *)appDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
- (XMPPStream *)xmppStream
{
return [[self appDelegate] xmppStream];
}
- (void)sendMessage:(id)sender
{
NSString *messageStr =messageField.text;
if([messageStr length] > 0)
{
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:messageStr];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:@"destination email address"];
[message addChild:body];
NSLog(@"%@",message);
[[self xmppStream] sendElement:message];
}
}
when you click on send button this method will be called and it shows log message as当您单击发送按钮时,将调用此方法并将日志消息显示为
<message type="chat" to="destination email address"><body>messageStr</body></message>
Assuming that the spaces after the <
characters shouldn't be there, it looks correct.假设
<
字符后面的空格不应该存在,它看起来是正确的。
You can even do without the from
attribute, since it'll be added by the server.您甚至可以不使用
from
属性,因为它将由服务器添加。
After fixing the syntax issues, removing the from
address, and removing the doubtfully-correct resource from the to
address, you're left with:在修复语法问题、删除
from
地址并从to
地址中删除可疑资源后,您将得到:
<message to='user1@server' type='chat'>
<body>TEST</body>
</message>
The resource on the to
address is like the issue. to
解决的资源就像问题一样。 Read XEP-0296 for how to deal with resources correctly when doing XMPP IM.阅读XEP-0296了解在进行 XMPP IM 时如何正确处理资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.