在iOS的XMPPFramework中,当连接成功时如何接收文件?

9

我希望使用TURNSocket在两个用户之间传输文件。

User1:(iPhone模拟器) User2:(Spark用户)

现在套接字已连接,我想通过Spark从User2向User1发送文件。iPhone模拟器可以接收这些消息:

<iq xmlns="jabber:client" id="P1J6b-29" to="User1@local/75694fce" from="User2@local/Spark 2.6.3"     type="set">
  <si xmlns="http://jabber.org/protocol/si" id="jsi_8334411215933911079" mime-type="image/png"
      profile="http://jabber.org/protocol/si/profile/file-transfer">
    <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="a2.png" size="12618">
      <desc>Sending 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>

我在XMPP在iPhone SDK中发送/接收文件...?主题看到了这些相关内容,告诉我们如何在didSucceed方法中处理,但我不知道如何在iPhone模拟器上接收由Spark用户发送的文件。
然后,在你的didSucceed实现中,使用传入的套接字发送数据:
- (void)writeData:(NSData *)data 
  withTimeout:(NSTimeInterval)timeout 
          tag:(long)tag;

最后,关闭套接字:
- (void)disconnectAfterWriting;

那么如何编写代码以在此方法或其他方法中接收文件?
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
    // Where is the NSData that can be find to used in writeData method ?
}

嗨,尼尔,你把这个东西搞定了吗? - Sunil Zalavadiya
1个回答

1
尝试使用FastSocket https://github.com/dreese/fast-socket。它非常适用于iPhone或服务器之间的TCP连接。请阅读文档(特别是单元测试),以获取详细的使用说明。您需要知道每个设备的IP地址才能相互连接。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接