Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive the file when connecting success in TURNSocket Of XMPPFramework in ios?

I want to use TURNSocket to transfer the file between the two users.

User1: (iphone sumulator) User2: (Spark user)

Now the socket has connected, and i want to send a file to User1 from User2 via the Spark. And the iphone sumulator can received these message:

<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>

I saw these in the XMPP Sending/Receving file in iphone sdk ...? topic about how to handle in didSucceed method, but i don't know how to receive the file that was sent by Spark user on the iphone sumulator.

Then, in your didSucceed implementation, send data on the socket that was passed in, using:

- (void)writeData:(NSData *)data 
  withTimeout:(NSTimeInterval)timeout 
          tag:(long)tag;

Finally, close the socket:

- (void)disconnectAfterWriting;

So how to code to receive the file in this method or others?

- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
    // Where is the NSData that can be find to used in writeData method ?
}
like image 673
Neil.Lv Avatar asked Dec 05 '11 08:12

Neil.Lv


1 Answers

Try FastSocket https://github.com/dreese/fast-socket. It is best for TCP connection between either iPhones or servers. Please read the docs as well (especially the Unit Tests) for a very detailed instruction on how to use it. You will need to know the IP's of each of the devices that are needed to connect to each other.

like image 59
Michael Avatar answered Oct 26 '22 10:10

Michael