TURN Connection using the iOS XMPPFramework and an OpenFire Server - ios

Problem : How can I get a successful TURN Connection using the iOS XMPPFramework and an OpenFire Server. I want to be able to send and recieve files.
Note : The base of my code is from the following tutorial : http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/
Update 13th April 2012 : After more research, I think the real relevant code I need to display in this question is this ...
This is where the TURNSocket attempts to connect
XMPPJID *jid = [XMPPJID jidWithString:#"myFriendsUsername#beta.myCompany.co.uk"];
NSLog(#"Attempting TURN connection to %#", jid);
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
However, when I debug through the code, in TURNSocket I get to a comment which states that "We were unable to find a single proxy server from our list". This is because the Array 'streamhosts' never gets populated. What could be the issue? Is there some XML somewhere that should tell me the problem? Is the issue likely to be with OpenFire?

The problem is caused if a full jID with a resource is not provided to TurnSocket.m! This is passed in in viewDidLoad of SMChatViewController
e.g Use
friendsUsername#beta.myCompany.co.uk/spark
rather than
friendsUsername#beta.myCompany.co.uk
My progress on this project can be followed here

This is the class method of TURNSocket you call to
populate the proxy candidates of the TURNSocket
stream host. So you should put streamhost back to
what it was before stream-host.
+ (void)setProxyCandidates:(NSArray *)candidates;
[TURNSocket setProxyCandidates:#["host1.somedomain.com", #"host2.someotherdomain.com"]];

In processRequestResponse.m in TurnSocket, the name of the streamhost element wasn't what OpenFire was giving me. I have changed it from this
NSXMLElement *streamhostUsed = [query elementForName:#"streamhost-used"];
to this
NSXMLElement *streamhostUsed = [query elementForName:#"streamhost"];
However, I now have a new error which I am starting a new question for ... OpenFire/XMPP 503 service-unavailable error (XEP-0065 using iOS XMPPFramework)
Update 20/4/2012 : I now believe this answer is wrong! If it was working correctly, streamhostUsed would be there, rather than streamhost with an error!

Related

ConnectionID is in incorrect formate. SignalR

I usesignalR latest library. I downloaded signalR library from gitHub SignalR gitHub link and installed pod file in my app. I am working on iOS end. I don't know about asp.net. The only url is provided to me for integration. Here is my code
__weak SRConnection *connection = [SRConnection connectionWithURL:SIGNALR_PATH];
[connection addValue:[[NSUserDefaults standardUserDefaults] objectForKey:kAccessToken] forHTTPHeaderField:#"MyAuthentication"];
connection.received = ^(NSString * data) {
NSLog(#"%#",data);
};
connection.started = ^{
[connection send:#"hello world"];
};
[connection start];
Connection open successfully but When I get try to send message it gives me an error "The ConnectionId is in incorrect format".
I am using latest library of signalR. I don't know what I need to authorised. Is only url enough for that? Or will need to add accessToken that I get on login?.
Please help me what I need for integrating signalR. I searched a lot but couldn't find any clear information.

iOS Pusher doesn't work, client not connecting

This is for www.pusher.com.
iOS lib they provided is libPusher. After I installed and follow the first step, it just not working. I've heard a few people make it work. Is this library still alive or it doesn't support newer version of iOS?
PTPusher *client = [PTPusher pusherWithKey:#"app-key" delegate:self encrypted:NO]; // I assume this is "key" not "secret" there.
[client connect];
PTPusherChannel *channel = [client subscribeToChannelNamed:#"test"];
NSLog(#"Channel: %#, %d", channel, channel.isSubscribed);
I've implemented delegate methods to track status. After [client connect] called, the delegate method: - (BOOL)pusher:(PTPusher *)pusher connectionWillConnect:(PTPusherConnection *)connection trigged, but then nothing happened after this. No error messages, no success messages. Since the clint is not connecting, the channel is not subscribed either.
I've implemented pusher on JS and it worked. Since what I did is very basic client connection and there is nothing I can do about (At least from documents), so I assume maybe this library just not working anymore.
I was being dumb and ignored that the document said pusher client should be strong. Therefore, the solution should be:
#property(nonatomic) PTPusher *client;
self.client = [PTPusher ...];
...

iOS:XMPP: Typing indication not working with Different client

I am starting to develop one XMPP ios client using robbiehanson/XMPPFramework I tried to achieve user is tying.. ie Typing indicator. It is working when both the users are using ios client. When I tried to use multiple client ie one user is using iOS client and another user using Spark desktop clien, the typing indicator is not working.
//Send Typing notification
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:self.userprofile.jidStr];
// [message addChild:body];
// chat notifications
XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message];
[xmppMessage addComposingChatState];
[appDelegate.xmppStream sendElement:xmppMessage];
// For Receive Typing Notification
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
if ([message hasComposingChatState]) {
self.statusLabel.text=#"is typing...";
}
}
The Typing notification is working fine when both users using my iOS client. But when one using ios client and another user using different client, the Typing notification is not working,
Please provide me the best way to achieve this.
Replace following line
[xmppMessage addComposingChatState];
with
[xmppMessage addMarkableChatMarker];
Other code is fine. Try this.
You need to implement xmpp-0022 , in this way messaging apps implements typing, sent, delivered and seen status
http://xmpp.org/extensions/xep-0022.html#sect-idp643808

Trouble connecting to a google apps server via MailCore

I'm trying to connect to Google Apps email server via IMAP. The code I am using below, every time I try to connect I get the error: Parse error Anyone know the source of this error?
int port = 993;
CTCoreAccount *account = [[CTCoreAccount alloc] init];
BOOL success = [account connectToServer:#"imap.gmail.com"
port:port
connectionType:CTConnectionTypeStartTLS
authType:CTImapAuthTypePlain
login:login
password:password];
NSLog(#"Port: %d",port);
if (!success) {
NSLog(#"Connection failed, error: %#",[account.lastError localizedDescription]);
}
else {
NSLog(#"Connection succeeded");
}
There were two issues simultaneously going on here. The first was that my network had a firewall and that was the source of the Parse Error.
Second, when you need to connect to Google Maps IMAP server, you'll need to use the CTConnectionTypeTLS instead of CTConnectionTypeStartTLS, because the second one makes the server go bonkers.

iOS: XMPP Reconnect with Old School SSL connection

XMPPFramework provides an extension named XMPPReconnect for "accidental disconnections" and automatically reconnects the stream.
This works well on the setting of the normal connection:
[xmppStream connect:&error]
[xmppStream setHostPort:5222];
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
but not for this Old School SSL connection:
[xmppStream oldSchoolSecureConnect:&error]
[xmppStream setHostPort:5223];
allowSelfSignedCertificates = YES;
allowSSLHostNameMismatch = YES;
The error libxmlErrorDomain as error code 4 with the description Document is empty was thrown continuously,
sometimes, the error GCDAsyncSocketErrorDomain as error code 4 with description Read operation timed out also thrown.
Please suggest me the way to make the XMPPReconnect work on the Old School SSL connection.
P.S. The XMPP server is openfire and the PLAIN mechanism for authentication.
I don't think the Reconnect Extension of the XMPPFramework knows about old school ssl connection. IMHO you will have to modify 'XMPPReconnect.m' function 'maybeAttemptReconnectWithReachabilityFlags:' to do something like:
if(self.usesLegacyConnect)
[xmppStream oldSchoolSecureConnect:nil];
} else {
[xmppStream connect:nil];
}

Resources