0
votes

I am developing chat application using xmpp client. I can send and receive message when I login with one account. My problem is when i login with two different account i cannot send message using First login account. For sending message i tried the fallowing code:

 - (void)sendMessage:(id)sender
{  
    xmppStream=[[self appDelegate] xmppStream];

    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:jidStr];
        [message addChild:body];
         NSLog(@"%@",message);
     }

}

In this delegate method, i create stream object like fallowing

-(void)setUpStream
{
XMPPStream *xmppStream=[XMPPStream alloc] init]
}

when i second time login with another account then xmppStream object is associated with second account but not for First account.

so i can't send message using first account.can any one solve my problem plz and how to create two xmppStream objects for two accounts;

1

1 Answers

0
votes

The easiest way to do this is to create to xmppStream objects in your AppDelegate.

Call one xmppStreamOne and xmppStreamTwo.

You could even create an NSMutableArray of xmppStreams if you intent to log into many different different servers.

When you retrieve the xmppStream from the AppDelegate make sure to grab the right one.