0
votes

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.

3
There's not really spaces after the < characters?Zash
I'm assuming the OP used spaces so the tags would show up; I've enclosed them in a code block instead.jtbandes
Why are you using resource in the "to" jid? Try just to="user1@server"Maggie
Why are you using resource in the "to" jid? Try just to="user1@server"Maggie

3 Answers

1
votes

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.

1
votes
- (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>
0
votes

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.