【问题标题】:iPhone Jabber/XMPP client... "TURN Connection failed"iPhone Jabber/XMPP 客户端...“TURN 连接失败”
【发布时间】:2011-11-22 16:46:16
【问题描述】:

我正在尝试构建一个简单的 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];
}

有人可以帮忙吗? 谢谢。

【问题讨论】:

    标签: ios xmpp xmppframework


    【解决方案1】:

    没有理由将 TURN 用于正常消息传递。只有媒体流需要 TURN。只需使用XMPPFramework。有一些很好的入门指南。

    接下来,使用这种性质的代码来创建和发送节:

    XMPPMessage *msg = [XMPPMessage message];
    [msg addAttributeWithName:@"type" stringValue:@"chat"];
    [msg addAttributeWithName:@"to" stringValue:@"foo@example.com"];
    NSXMLElement *body = [NSXMLElement elementWithName:@"body" stringValue:@"Hello"];
    [msg addChild:body];
    [[self xmppStream] sendElement:msg];
    

    请注意,msg 只是 NSXMLElement 的子类,因此您可以随意修改 XML 来制作您要发送的协议。

    【讨论】:

    • 你能指出一些吗?我只找到了关于如何开始连接的文档——从来没有找到关于如何发送消息的文档。非常感谢。
    • 原来不需要TURN - 该错误与无法发送消息无关。我将 sendMessage 方法移到了 App Delegate 中,然后……它开始工作了。我不知道为什么。但它有效。
    • @Joe:- 你能给我在 iOS 中集成 XMPP 的参考,任何链接或文档吗?我对此不走运。
    • 嗨,Joe,你能给我一些在 XMPP 中发送文件的方法吗?
    • xmpp.org/xmpp-protocols/xmpp-extensions 上查看 XEP 列表。从 XEP-0096 开始:xmpp.org/extensions/xep-0096.html
    猜你喜欢
    • 2011-01-31
    • 2012-04-09
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2022-11-30
    • 2010-12-26
    • 1970-01-01
    相关资源
    最近更新 更多