XMPP 1 to 1 chat query?
I am developing a chat project using Openfire.
I have done with group chatting.
But confusion is in 1 to 1 chat.
I am using:
<message开发者_如何学JAVA from='user2@server/user2' to='user1@server/user1' type='chat'>
<body>TEST< /body>
</message>
but it does not send it.
Thanks in advance.
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.
- (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>
After fixing the syntax issues, removing the from
address, and removing the doubtfully-correct resource from the to
address, you're left with:
<message to='user1@server' type='chat'>
<body>TEST</body>
</message>
The resource on the to
address is like the issue. Read XEP-0296 for how to deal with resources correctly when doing XMPP IM.
精彩评论