我正在尝试使用XMPPFramework和OpenFire在iOS上进行XMPP文件传输。我的代码基础来自以下tutorial。我已经成功建立了一个TurnSocket(XEP-0065: SOCKS5 Bytestreams)连接,但我不知道如何使用它来发送数据。我有两个考虑因素,都卡住了:1.调用[socket writeData]和2.使用“XEP-0096: SI File Transfer”。
可能的解决方案1 - 调用[socket writeData]
在我的应用程序委托中,我有一个didSucceed方法。我可以像这样调用[socket writeData]...
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
NSLog(@"TURN Connection succeeded!");
[socket writeData:myData withTimeout:60.0f tag:0];
[turnSockets removeObject:sender];
}
更新于6月14日:这是否正确?如果是,那么另一个用户如何读取数据?我尝试过实现
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
但它从未被调用。我该如何确保它被调用?
可能的解决方案2-XEP-0096:SI文件传输 我需要使用XEP-0096:SI文件传输吗?如果需要,那么我如何在我需要构建的XEP-0096 XML中使用我的成功连接? XEP-0096文档 暗示存在一个“哈希”属性,但我不知道这是从哪里来的。
例如。
<iq type='set' id='offer1' to='receiver@jabber.org/resource'>
<si xmlns='http://jabber.org/protocol/si'
id='a0'
mime-type='text/plain'
profile='http://jabber.org/protocol/si/profile/file-transfer'>
<file xmlns='http://jabber.org/protocol/si/profile/file-transfer'
name='test.txt'
size='1022'
hash='552da749930852c69ae5d2141d3766b1'
date='1969-07-21T02:56:15Z'>
<desc>This is a test. If this were a real file...</desc>
</file>
<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>
hash
是文件内容的 MD5。请参阅 XEP-0096 第3节。 - Flow