I am developing a chat app in iOS using xmpp server. When i tried to connect to the server it returned 0 without any exception. All server credentials are true to the best of my knowledge. I tried many a times but couldn't found any fruitful help. Kindly give me a direction what should I do. Here is a code below.
xmppStream = [[XMPPStream alloc] init];
// [self setupStream];
NSXMLElement *presence = [NSXMLElement elementWithName:#"presence"];
[xmppStream sendElement:presence];
[xmppStream setMyJID:[XMPPJID jidWithString:#"app.com"]];
[xmppStream setHostName:#"appname.com"];
[xmppStream setHostPort:5222];
NSError *error2;
if ([xmppStream connect:&error2])
{
NSLog(#"Connected to XMPP.");
}
else
{
NSLog(#"Error connecting to XMPP: %#",[error2 localizedDescription]);
}
[self xmppStreamDidConnect:xmppStream];
//method is
- (void)setupStream {
NSLog(#"setupStream in delegate");
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
self.xmppStream.hostName = #"appname.com";
self.xmppStream.hostPort = (port);
[self connect];
}
Follow the connection class given in this link
Connection to server returns “0” only when you specify wrong HostName, HostPort or JID.
And one more thing you need not call xmppStreamDidConnect explicitly it will be called as delegate from XMPPFramework.
Related
Trying to create a very simple proof of concept iOS xmpp app with the robbiehanson xmpp frame work, just need to be able to send and receive messages and roster data. I can authenticate and send messages successfully, but when users attempt to respond to my messages I do not receive them. I have implemented the didReceiveMessage delegate method as follows:
-(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message {
NSLog(#"incoming message: %#", message);
}
but I never receive this log. If I log in with the existing web app or android app that communicates with this xmpp server I receive these messages, so I'm inclined to believe they are formatted properly. Is there a module I need to add to the XMPPStream for receiving messages? I'm setting up the stream like this (some of the string values have been changed for security and what not):
stream = [[XMPPStream alloc] init];
stream.enableBackgroundingOnSocket = YES;
stream.hostName = #"hostname.com";
stream.hostPort = 5222;
XMPPRosterCoreDataStorage* xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore];
XMPPRoster* xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
xmppRoster.autoFetchRoster = YES;
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
[stream addDelegate:self delegateQueue:dispatch_get_main_queue()];
XMPPJID* jid = [XMPPJID jidWithUser:#"username" domain:#"domain.com" resource:#"iOS"];
[stream setMyJID:jid];
[xmppRoster activate:stream];
[stream connectWithTimeout:XMPPStreamTimeoutNone error:&error]
and then in the xmppStreamDidConnect method I do this to authenticate
NSString *myPassword = #"password";
NSError *error = nil;
[stream authenticateWithPassword:myPassword error:&error]
When I am sending a message out I use this snippet:
MPPJID* recipient = [XMPPJID jidWithString:#"user#domain.com"];
XMPPMessage* message = [[XMPPMessage alloc] initWithType:#"chat" to:recipient];
[message addBody:#"hello world"];
[stream sendElement: message];
I'm thinking there is something simple I am missing that someone who has used this before will be able to point out to me right away. I'm ready to supply other info if necessary for solving this issue.
I simply needed to broadcast my presence, then I was able to receive messages.
I added these lines to the streamDidAuthenticate method
XMPPPresence *presence = [XMPPPresence presence];
[sender sendElement:presence];
I am attempting to connect to an ejabberd server hosted here:
198.199.106.154:5280
The issue is that this block of code is not calling iOS XMPP Framework's delegate:
- (void)xmppStreamDidConnect:(XMPPStream *)sender
I am confident that my server has made a connection because the following log appears on the server after the code has executed:
- (void)setupStream {
xmppStream = [[XMPPStream alloc] init];
xmppStream.hostName = #"198.199.106.154";
xmppStream.hostPort = 5280;
NSString * jabberID = [[NSString alloc] initWithFormat:#"admin#%#", #"localhost"];
[xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
NSError *error2 = nil;
[xmppStream connectWithTimeout:10.0f error:&error2];
NSLog(#"here is the connect error %#", [error2 localizedDescription]); //NO ERROR IS CALLED!
dispatch_async(dispatch_get_main_queue(), ^{
[self authWithServer];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(authWithServer) userInfo:nil repeats:YES];
//I GET THE FOLLOWING MESSAGE:: "Please wait until the stream is connected"
});
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
I am absolutely lost folks! Any guidance would be immensely helpful
XMPPFramework uses standard XMPP TCP connection (which handled by ejabberd_c2s module usually on 5222 port), but you are trying connect to http-bind module, which is not implemented in XMPPFramework.
I am implementing a chat application.
I want to transfer a file but I keep getting TURN Connection failed! I am using the below code:
XMPPJID *jid = [XMPPJID jidWithString:#"user#krishanyadav.local/resourceID"] ;
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
[turnSockets addObject:turnSocket];
[TURNSocket setProxyCandidates:#[JABBER_DOMAIN_NAME, JABBER_DOMAIN_NAME]];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
NSLog(#"TURN Connection succeeded!");
NSLog(#"You now have a socket that you can use to send/receive data to/from the other person.");
[turnSockets removeObject:sender];}
- (void)turnSocketDidFail:(TURNSocket *)sender {
NSLog(#"TURN Connection failed!");
[turnSockets removeObject:sende
}
how can I transfer the file using iOS xmpp jabber2 server.
NOTE: I am able to send a file from Audim to iMessage messenger (from and to each other) from the server.
For changing my logged status I used the following code:
XMPPPresence *presence = [XMPPPresence presenceWithType:#"away"];
[[self xmppStream] sendElement:presence];
But I am not getting the reference of [self xmppStream]. So I changed to the following code:
XMPPPresence *presence = [XMPPPresence presence];
NSXMLElement *status = [NSXMLElement elementWithName:#"status"];
[status setStringValue:#"away"];
[presence addChild:status];
NSError *error = nil;
xmppStream = [[XMPPStream alloc] init];
[xmppStream disconnect];
NSString *myJID = [NSString stringWithFormat:#"%#", appDelegate.jid];
XMPPJID *JID;
JID = [XMPPJID jidWithString:myJID];
NSLog(#"%#",JID);
[xmppStream setMyJID:JID];
xmppStream.hostName=#"talk.google.com";
[xmppStream connect:&error];
[xmppStream sendElement:presence];
Still not getting the changed status. Please share your ideas. Thanks in advance.
You can change your status immediately after you're logged in via goOnline method as it is called after xmppStreamDidAuthenticate.
- (void)goOnline
{
// Initialize XMPPPresence variable
XMPPPresence *presence = [XMPPPresence presence];
// Initialize XML element <show/> for specifying your status
NSXMLElement *show = [NSXMLElement elementWithName:#"show"];
// Initialize XML element <status/> for describing your status
NSXMLElement *status = [NSXMLElement elementWithName:#"status"];
// If you want your user status to be shown as "Available"
[show setStringValue:#"chat"];
[status setStringValue:#"Available"];
// If you want your user status to be shown as "Busy"
[show setStringValue:#"dnd"];
[status setStringValue:#"Busy"];
// If you want your user status to be shown as "Away"
[show setStringValue:#"away"];
[status setStringValue:#"Away"];
// If you want your user status to be shown as "Off-day"
[show setStringValue:#"xa"];
[status setStringValue:#"Off-day"];
// Add the XML elements to XMPPPresence
[presence addChild:show];
[presence addChild:status];
// Update new presence to server
[xmppStream sendElement:presence];
}
For more information and an explanation to my code above, visit Change XMPPPresence to Away/Busy/Invisible.
You have to wait until after you're connected to send stanzas, by listening for xmppStreamDidAuthenticate on the delegate.
Also, don't bother to set the to or from JID when broadcasting your presence.
I have a Problem with the XMPP-Framework for iOS. Every Time I fire registerWithPassword Method i get an Error:
"Error Domain=XMPPStreamErrorDomain Code=1 "Please wait until the
stream is connected." UserInfo=0xad7c300
{NSLocalizedDescription=Please wait until the stream is connected.} "
I do the following steps in my Code:
-(void)createUserWithUsername:(NSString*)name andPW:(NSString*)pw{
[self setupStream];
NSLog(#"name: %# ",name);
NSString *nameFor = name;
[self disconnect];
NSString *jidBenutzer = [NSString stringWithFormat:#"%##my-Server.com",nameFor];
NSError *error = nil;
NSError * err = nil;
NSLog(#"jabberid : %#",jidBenutzer);
XMPPJID *jid = [XMPPJID jidWithString:jidBenutzer];
self.xmppStream.myJID = jid;
[[self xmppStream] registerWithPassword:pw error:&err];
NSLog(#"Connection: %#",error);
NSLog(#"Register: %#",err);
}
I hope you can help me !
From your example code, I do not see any call to:
[xmppStream connect:&error]
From the error message, you are actually not connected.
Make sure you correctly call the connect method and that you are processing the error accordingly.
/**
* This method attempts to register a new user on the server using the given username and password.
* The result of this action will be returned via the delegate methods.
*
* If the XMPPStream is not connected, or the server doesn't support in-band registration, this method does nothing.
**/
This is the below.
- (BOOL)registerWithPassword:(NSString *)password error:(NSError **)errPtr
The method's instructions . You will find that before you use this method , you have to connecting the server.
I can' not find below.
[xmppStream connect:&error]
I use the this.
NSError *error;
NSString *tjid = [[NSString alloc] initWithFormat:#"anonymous#%#", serverName];
isRegister = YES;
[xmppStream setMyJID:[XMPPJID jidWithString:tjid]];
[xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]
Please make sure your openfire server is turned on from your system preferences.
It is a late answer but still for any new developer like me: You have to login anonymously before registration: For example you are login with yourname#yourserver and your password try to login with unknown#yourserver and for password put nothing. So it will connect the stream but will not authenticate this is required for registration.
The stream should be connected but not be authenticated.