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.
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 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.
I'm trying to implement the XMPPFramework by robbiehanson. The problem is, that I get the following error message:
Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0x9517440 {NSLocalizedDescription=Socket closed by remote peer}
I already tried everything I could find on the internet (XMPPPing etc.) but nothing could fix my problem. Here is the code I'm using:
- (void)connect {
stream = [[XMPPStream alloc] init];
[stream setEnableBackgroundingSocket:YES];
[stream addDelegate:self delegateQueue:dispatch_get_main_queue()];
reconnect = [[XMPPReconnect alloc] init];
[reconnect activate:stream];
[stream setHostName:_hostName];
[stream setPort:5223];
[stream setMyJID:[XMPPJID jidWithString:_username];
NSError *e;
if(![stream connectWithTimeout:20 error:&e]) {
NSLog(#"%#", e);
}
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
NSError *e;
[sender authenticateWithPassword:_password];
if(e) {
NSLog(#"%#", e);
}
}
I'm getting this error message immediately, not after several seconds. I already thought it might be, because our server requires SSL, but the only solution I found for SSL was running [stream secureConnection:nil]; and this only works if connected.
I also never get the -xmppStreamDidConnect: delegate method.
stream oldSchoolSecureConnectWithTimeout: will connect to 5223/SSL
i am establishing a UDP connection using GCDAsyncSocket(ios device). Everything working fine and im able to send and receive messages, my problem is that i want to exchange data fast. I can send pretty fast data from my iphone to a pc but i cant get at that speed data from pc, more specific i want to be able to get data every 100ms.
I use this function when i connect successfully:
-(void)startRead {
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(startRead) userInfo:nil repeats:YES];
[asyncSocket readDataWithTimeout:-1 tag:0];
}
With this i can read data with 1sec interval but if i try to put 0.1 seconds my program freezes.(Same with values under 1second) Im sure that im doing something wrong here and there will be a way to achieve what i want so if anybody know plz help!!
thanx
I believe the above comment is correct, you've not set the Delegate correctly on init. The socket creation should be something like this
GCDAsyncUdpSocket* udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *error = nil;
if (![udpSocket bindToPort:0 error:&error])
{
[self logError:[NSString stringWithFormat:#"Error binding: %#", error]];
return;
}
if (![udpSocket beginReceiving:&error])
{
[self logError:[NSString stringWithFormat:#"Error receiving: %#", error]];
return;
}
NSString *_host = nil;
uint16_t _port = 0;
[GCDAsyncUdpSocket getHost:&_host port:&_port fromAddress:udpSocket.localAddress];
[self logInfo:[NSString stringWithFormat:#"Socket setup on host %#:%d", _host, _port]];
[self logInfo:#"Socket created successfully."];
Unless you're using a different version of GCDAsyncUdpSocket than I'm familiar with, the correct callback method is actually the below method. This is called automatically when the delegate is set and a packet is received on the correct port.
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext
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.