TURN Connection using the iOS XMPPFramework and an

2019-08-25 06:06发布

问题:

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?

回答1:

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



回答2:

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"]];


回答3:

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!