我正在尝试构建一个简单的 Jabber 客户端。我已经下载了这个示例项目,它使用xmpp-framework https://github.com/funkyboy/Building-a-Jabber-client-for-iOS 我在 iOS 模拟器中运行它。我已经在本地安装了 Openfire,以便我可以与登录 iChat 的用户进行交互。
不幸的是,该应用程序只接收消息。它无法发送消息并给出错误“TURN Connection failed!”。
这是尝试连接的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tView.delegate = self;
self.tView.dataSource = self;
[self.tView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
messages = [[NSMutableArray alloc ] init];
JabberClientAppDelegate *del = [self appDelegate];
del._messageDelegate = self;
[self.messageField becomeFirstResponder];
XMPPJID *jid = [XMPPJID jidWithString:@"user@server.local"];
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];
}
这些是关于成功/失败的方法:
- (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:sender];
}
有人可以帮忙吗?谢谢你。