简体   繁体   中英

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 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM