I am working on a chat application where I set my xmppHostName- 'myserver' and server port -5222. First I created a user on xmpp through my application and it got registered on xmpp but there was an authentication error (although my user id and password were both same). Then I solved this authentication issue by using following method-
NSError *authenticateError = nil;
XMPPPlainAuthentication *plainAuth = [[XMPPPlainAuthentication alloc] initWithStream:self.xmppStream password:password];
if (![_xmppStream authenticate:plainAuth error:&authenticateError]) {
NSLog(#"Authentication errorrrr: %#", authenticateError.localizedDescription);
}
and the authentication error is gone, and my user is online but when I try to send any messages, the server replies with an error through otherserver:
<message xmlns="jabber:client" id="ACC2AAA6-42CE-4590-95A0-C4B28BE9BF04" to="97#otherserver/4ywme5xjh0" from="62#myserver" type="error"><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></message>
where, 97 is my user id and 62 is front users id. Below is my code for sending xmpp message:
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:messageBody];
NSXMLElement *subject = [NSXMLElement elementWithName:#"subject"];
[subject setStringValue:subjectName];
[message addAttributeWithName:#"to" stringValue:[user stringByAppendingString:myserver]];
[message addChild:body];
[message addChild:subject];
[self.xmppStream sendElement:message];
Here, 'myserver' is my server's hostname and the server replies from another server 'otherserver'. I am sure that I am not setting this 'otherserver' anywhere in my application, then how is this possible that it replies through it?
Related
I'm new for ejabberd. I want to add new user on server through my iOS App.
I tried with many code that was find out from the Google but no one can solve my issue.
I set module to http://localhost:5280/admin/server/localhost/node/ejabberd#localhost/modules/
For enable mod_register also change ejabberd.yml file from etc/ejabberd folder.
And my Listened Ports at ejabberd#localhost
And I used below code for register user.
NSXMLElement *query = [NSXMLElement elementWithName:#"query" xmlns:#"jabber:iq:register"];
[query addChild:[NSXMLElement elementWithName:#"username" stringValue:#"syam"]];
[query addChild:[NSXMLElement elementWithName:#"password" stringValue:#"Vrin#123"]];
NSXMLElement *iq = [NSXMLElement elementWithName:#"iq"];
[iq addAttributeWithName:#"type" stringValue:#"set"];
[iq addAttributeWithName:#"id" stringValue:#"reg2"];
[iq addChild:query];
[APP_DELEGATE.xmppStream sendElement:iq];
[APP_DELEGATE.xmppStream setHostName:#"0.0.0.0"];
[APP_DELEGATE.xmppStream setHostPort:5222];
NSError *error;
if (![APP_DELEGATE.xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error connecting"
message:#"See console for error details."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}
But didn't get success and occurred below error message.
<iq xmlns="jabber:client" from="himanshu#localhost" to="himanshu#localhost/15505992182228745748626" type="error" id="reg2"><query xmlns="jabber:iq:register"><username>syam</username><password>Vrin#123</password></query><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></service-unavailable><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">No module is handling this query</text></error></iq>
Please help me to solve my issue.
access: register means - only already registered users are able to access mod_register (to change password, for example). You need to have access: all to allow registration. And do not forget to protect registration with CAPTCHA when server will be opened for public network (and in this case that simple registration implementation in XMPPFramework will not enough)
Also it's not clear is mod_register enabled for your virtualhost, check mod_register presence in modules: block of your configuration
I have set up ejabberd server on localhost, then I registered an account on Adium by selecting XMPP (jabber) server on port 5222. After that I configured an account on mobile test app and sent messages between two users (Adium/test app) successfully. But I am facing an issue(no error messages in console) while sending image from my test app to Adium. It is not received on Adium.
NSData *dataF = UIImageJPEGRepresentation(imageName, 0.0);
NSString *imgStr = [dataF base64EncodedStringWithOptions: 0];
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:#"123"];
NSXMLElement *ImgAttachement = [NSXMLElement elementWithName:#"attachment"];
[ImgAttachement setStringValue: imgStr];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:jid];
[message addChild:body];
[message addChild:ImgAttachement];
[self.xmppStream sendElement:message];
Any help would be much appreciated.
We saw a similar issue in our ios app. I think you need to somehow add the two users as friends/contacts and make sure you have enabled mod_vcard_xupdate module in ejabberd config file. See if that helps.
I am able to send messages to users which means i have a working and authenticated xmppStream.
But i am unable to send and receive acknowledgement from server. I want to know which message was received successfully by the server. I googled and found that XEP-0198 should be implemented for this. I am using ejabberd as XMPP server and it supports XEP-0198.
I tried that but i don't know if i am doing it right or not.
First of all i included the header file and added XMPPStreamManagementDelegate.
#import "XMPPStreamManagement.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate,XMPPStreamManagementDelegate>
In the implementation file, here's how i have defined the stream.
XMPPStream *xmppS = [[XMPPStream alloc] init];
[xmppS addDelegate:self delegateQueue:dispatch_get_main_queue()];
XMPPStreamManagement *xsm = [[XMPPStreamManagement alloc] init];
[xsm addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xsm activate:xmppS];
After that i connect with the server. After the connection is successful, i send an enable stanza.
NSXMLElement *enable = [NSXMLElement elementWithName:#"enable" xmlns:#"urn:xmpp:sm:3"];
[xsm.xmppStream sendElement:enable];
Then i send a message
NSXMLElement *a = [NSXMLElement elementWithName:#"request" xmlns:#"urn:xmpp:receipts"];
XMPPElement *e = [[XMPPElement alloc] initWithName:#"message"];
[e addAttributeWithName:#"id" stringValue:#"123456"];
[e addAttributeWithName:#"type" stringValue:#"chat"];
[e addAttributeWithName:#"to" stringValue:#"testuser#myxmppserver.com"];
[e addAttributeWithName:#"from" stringValue:#"testuser2#myxmppserver.com"];
[e addChild:a];
[xsm.xmppStream sendElement:e];
Test User receives the message and Test User 2 gets the received stanza.
<received xmlns="urn:xmpp:receipts" id="123456"/>
My problem is if i send the following stanza, i receive no message.
NSXMLElement *r = [NSXMLElement elementWithName:#"r"];
[xsm.xmppStream sendElement:r];
I have implemented the following function
-(void)xmppStreamManagementDidRequestAck:(XMPPStreamManagement *)sender
{
NSLog(#"ACK");
}
But still nothing gets printed.
Please help. Also, how can i know when the server has received the sent message.
Let me know if anyone wants to know any other part of code from my side.
You can use the functions in xmppStreamManagement for sending the request and get received id:
[xmppStreamManagement requestAck];
and
- (void)xmppStreamManagement:(XMPPStreamManagement *)sender wasEnabled:(NSXMLElement *)enabled
- (void)xmppStreamManagement:(XMPPStreamManagement *)sender didReceiveAckForStanzaIds:(NSArray *)stanzaIds
make sure the stream management is enabled by:
[self.xmppStreamManagement enableStreamManagementWithResumption:YES maxTimeout:0];
I am new to XMPP. I'm using XMPP and Open fire server for my chat app. The application is working but now I want to get message delivery receipt. I'm using the following code for that,
in setupStream:
xmppMessageDeliveryRecipts = [[XMPPMessageDeliveryReceipts alloc] initWithDispatchQueue:dispatch_get_main_queue()];
xmppMessageDeliveryRecipts.autoSendMessageDeliveryReceipts = YES;
xmppMessageDeliveryRecipts.autoSendMessageDeliveryRequests = YES;
[xmppMessageDeliveryRecipts activate:xmppStream];
And in sendMessage:
NSString *messageID=[xmppStream generateUUID];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"id" stringValue:messageID];
[message addAttributeWithName:#"to" stringValue:myJID];
[message addChild:body];
But i can't get message delivery receipt. How can I get it? Anybody knows?
You are already receiving delivery receipt responses, but XMPPMessageDeliveryReceipts module does not handle it automatically. You need to store all incoming and outgoing messages (check XMPPMessageArchiving module, it can save messages in the XMPPMessageArchiving_CoreDataStorage instance), check if message hasReceiptResponse (defined in XMPPMessage+XEP_0184 category), find the message id in the receipt response and mark corresponding message as "delivered" in the message storage (you may need to add new property e.g. "delivered" to XMPPMessageArchivingCoreDataObject if you will use this module, or make your own storage mechanism)
I am using XMPP in my app. My messages are not being sent whenever I attempt to send a message to any specific ID (for example 'test.codemen#gmail.com' in my code).
My code is given below. Thanks in advance.
- (IBAction)sendMsg:(id)sender
{
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:msgField.text];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:#"test.codemen#gmail.com"];
[message addChild:body];
iPhoneXMPPAppDelegate *share = [iPhoneXMPPAppDelegate sharedInstance];
[[share xmppStream] sendElement:message];
}
your code looks fine to me.
Google Talk routes messages only to contacts you are subscribed to. Is the user you send the message to on your contact list?
Print the xml , then see what's in the message .Maybe you are sending message to a wrong JID .