我正在开发聊天应用程序.现在我想使用TurnSocket类发送文件,但套接字无法连接.
- (void)sendToOtherDevice:(NSData *)fileData receiverJid:(NSString *)receiverJid {
XMPPJID *JID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@/%@",receiverJid,resourceID]];
NSLog(@"%@",[JID full]);
NSLog(@"Attempting TURN connection to %@", JID);
[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:JID.domain, nil]];
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:JID];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
Run Code Online (Sandbox Code Playgroud)
TurnSocket委托方法
- (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];
}
Run Code Online (Sandbox Code Playgroud)
日志:
发送:
<iq type="get" to="meinantrieb.net" id="C6CF8EEE-B74E-45C8-8881-89BD0835056E">
<query xmlns="http://jabber.org/protocol/disco#items"/></iq>
Run Code Online (Sandbox Code Playgroud)
RECV:
<iq xmlns="jabber:client" from="meinantrieb.net" to="kirit@meinantrieb.net/267698820914007696033596" id="C6CF8EEE-B74E-45C8-8881-89BD0835056E" type="result">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="conference.meinantrieb.net"/>
<item jid="irc.meinantrieb.net"/>
<item jid="proxy.meinantrieb.net"/>
<item jid="pubsub.meinantrieb.net"/>
<item jid="vjud.meinantrieb.net"/></query></iq>
Run Code Online (Sandbox Code Playgroud)
发送:
<iq type="get" to="proxy.meinantrieb.net" id="22D98197-F1F2-4D8F-AA9C-E1076D0EF9F7">
<query xmlns="http://jabber.org/protocol/disco#info"/></iq>
Run Code Online (Sandbox Code Playgroud)
RECV:
<iq xmlns="jabber:client" from="proxy.meinantrieb.net" to="kirit@meinantrieb.net/267698820914007696033596" id="22D98197-F1F2-4D8F-AA9C-E1076D0EF9F7" type="result">
<query xmlns="http://jabber.org/protocol/disco#info">
<identity category="proxy" type="bytestreams" name="SOCKS5 Bytestreams"/>
<feature var="http://jabber.org/protocol/disco#info"/>
<feature var="vcard-temp"/>
<feature var="http://jabber.org/protocol/bytestreams"/>
<x xmlns="jabber:x:data" type="result">
<field var="FORM_TYPE" type="hidden">
<value>http://jabber.org/network/serverinfo</value></field></x></query></iq>
Run Code Online (Sandbox Code Playgroud)
发送:
<iq type="get" to="proxy.meinantrieb.net" id="84AFA217-7F71-48B4-B56C-66995FE20490">
<query xmlns="http://jabber.org/protocol/bytestreams"/></iq>
Run Code Online (Sandbox Code Playgroud)
RECV:
<iq xmlns="jabber:client" from="proxy.meinantrieb.net" to="kirit@meinantrieb.net/267698820914007696033596" id="84AFA217-7F71-48B4-B56C-66995FE20490" type="result">
<query xmlns="http://jabber.org/protocol/bytestreams">
<streamhost jid="proxy.meinantrieb.net" host="0.0.0.0" port="7777"/></query></iq>
Run Code Online (Sandbox Code Playgroud)
发送:
<iq type="set" to="vote@meinantrieb.net/(null)" id="694B5F07-3A70-4556-9268-1D47AC251229">
<si xmlns="http://jabber.org/protocol/si" id="694B5F07-3A70-4556-9268-1D47AC251229" profile="http://jabber.org/protocol/si/profile/file-transfer">
<file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="abc.txt" size="2239350"/>
<feature xmlns="http://jabber.org/protocol/feature-neg">
<x xmlns="jabber:x:data" type="form">
<field var="stream-method" type="list-single"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si></iq>
Run Code Online (Sandbox Code Playgroud)
RECV:
<iq xmlns="jabber:client" from="vote@meinantrieb.net/(null)" to="kirit@meinantrieb.net/267698820914007696033596" type="result" id="694B5F07-3A70-4556-9268-1D47AC251229">
<si xmlns="http://jabber.org/protocol/si">
<feature xmlns="http://jabber.org/protocol/feature-neg">
<x xmlns="jabber:x:data" type="submit">
<field var="stream-method"><value>http://jabber.org/protocol/bytestreams</value></field></x></feature></si></iq>
Run Code Online (Sandbox Code Playgroud)
发送:
<iq type="set" to="vote@meinantrieb.net/(null)" id="694B5F07-3A70-4556-9268-1D47AC251229"><query xmlns="http://jabber.org/protocol/bytestreams" sid="694B5F07-3A70-4556-9268-1D47AC251229" mode="tcp">
<streamhost xmlns="http://jabber.org/protocol/bytestreams" jid="proxy.meinantrieb.net" host="0.0.0.0" port="7777"/></query></iq>
Run Code Online (Sandbox Code Playgroud)
RECV:
<iq xmlns="jabber:client" from="vote@meinantrieb.net/(null)" to="kirit@meinantrieb.net/267698820914007696033596" type="error" id="694B5F07-3A70-4556-9268-1D47AC251229">
<error code="404" type="cancel">
<item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
Run Code Online (Sandbox Code Playgroud)
TURN连接失败!
任何帮助或建议将不胜感激.
最好先集中精力让两个 jabber 客户交谈,因为据我所知,与其他客户沟通存在很多问题。(即 Adium、Spark)
现在可以在两个 jabber 客户端之间建立连接。连接到其他 jabber 客户端(例如 Adium 或 Spark)确实存在一些问题。
对于要连接的两个 jabber 客户端,一个必须是服务器(目标),一个必须是客户端(请求者)。
因此,我们需要实现来自另一个客户端的传入请求。为了实现这一点,我们需要几行代码来处理传入的 TURN 请求。
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
DDLogVerbose(@"%@: %@ - %@", THIS_FILE, THIS_METHOD, [iq elementID]);
if ([TURNSocket isNewStartTURNRequest:iq]) {
NSLog(@"IS NEW TURN request..");
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] incomingTURNRequest:iq];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
如果您在两个 jabber 客户端上进行测试,您将能够从任一侧建立连接。从 Spark 接收数据没有问题,但发送数据仍然出现 406 错误。无论哪种方式都无法与 Adium 通信。
我的建议:
归档时间: |
|
查看次数: |
3228 次 |
最近记录: |