XMPP Sending/Receving file in iphone sdk ...?
Asked Answered
S

3

3

How to send/receive file in iphone sdk using xmpp framework ? Currently i am using XEP-0065 classes, and use the following code:

ObjTURNSocket = [[TURNSocket alloc] initWithStream:((TestAppDelegate*)[[UIApplication sharedApplication] delegate]).xmppStream 
                                                 toJID:chatuser.jid];
    [ObjTURNSocket start:self];

And I am getting following response from the server:

<iq type="error" id="AB2ED567-B97F-4DFE-B789-7731A617C239" to="kapil@testweb/6df6dc96" from="jabber.org">
   <query xmlns="http://jabber.org/protocol/disco#items"/>
   <error code="404" type="cancel">
      <remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
   </error>
 </iq>`

Any help or suggestion will be well appreciated.

Soundproof answered 13/6, 2011 at 9:14 Comment(3)
I am looking for a tutorial for sending/reeving files in xmpp using XEP-0065 extension class - TURNSocket.h & TURNSocket.mSoundproof
What version of XMPPFramework are you using? The current version has startWithDelegate: instead of start:. Also, what is the value of chatuser.jid?Kiakiah
In my class there is also a method named startWithDelegate, but can you give me idea where to pass file contents in TURNSocket class.Soundproof
K
4

First, call setProxyCandidates with an array of the possible servers that you might be able to use for proxying. The default is "jabber.org", and your server is not federated with jabber.org, which is why you are getting the disco error back.

Next, in your delegate, implement the following methods:

- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket;
- (void)turnSocketDidFail:(TURNSocket *)sender;

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;

I figured this out by looking at the source for TURNSocket.m, looking for the hardcoded "jabber.org", then searching for [delegate to find the places the delegate was getting called. This took me back to TURNSocket.h, which had a protocol documented for the delegate to implement.

Kiakiah answered 14/6, 2011 at 7:34 Comment(9)
What if i don't want to use proxying, i am not using any proxy server ? If i pass [setProxyCandidates:nil] then turnSocketDidFail called...! Even i have also tried passing server IP but then also turnSocketDidFail method called. So now what should i pass in "SetProxyCandidates" ?Soundproof
when i pass server name in [setProxyCandidates : servername]: SEND: <iq type="set" to="shiv@triforceweb" id="D9305C67-5713-4804-BA8E-863EA8B2AAEE"><query xmlns="jabber.org/protocol/bytestreams" sid="D9305C67-5713-4804-BA8E-863EA8B2AAEE" mode="tcp"><streamhost jid="proxy.triforceweb" host="192.168.1.11" port="7777"/></query></iq>Soundproof
RECV: <iq type="error" id="D9305C67-5713-4804-BA8E-863EA8B2AAEE" from="shiv@triforceweb" to="kapil@triforceweb/594a81f"><query xmlns="jabber.org/protocol/bytestreams" sid="D9305C67-5713-4804-BA8E-863EA8B2AAEE" mode="tcp"><streamhost jid="proxy.triforceweb" host="192.168.1.11" port="7777"/></query><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>Soundproof
If you don't want do to proxying, you should use some other code than this. You could do XEP-47, but that doesn't scale well. If you're on the same network, you can just set up a one-shot web server, and pass an HTTP URL to the other side.Kiakiah
Thanks Joe, thanks for reply. I am thinking of another way, for eg. suppose user(A) want to send file to user(B), so user(A) upload that file to server and in response get uploaded file url from server. Now user(A) send custom message of type "FILE_TRANSFER" contains uploaded file url (with name) to user(B). On receiving custom message of type "FILE_TRANSFER" to user(B), he/she has three options, either accept or reject or do-nothing.Soundproof
If user(B) accept file req. then file downloaded from url to user(B) device. and after download webservice will be called for removing that file from server. If user(B) rejects file, then i can remove file from server directly. and if user(B) do nothing, then after end of current session that file will be removed from web-server.Soundproof
I know this is not the best option at all, but this will be my last choice. Does it looks ok ?Soundproof
@JoeHildebrand: I am facing same error can you please tell me how can i solve it? i have checked above answers and comments but not gettingTreatment
@Treatment you need to send "jabberID@domain/resource" in the 'to' field then only server recognise the user on jabber server while init file transferIlbert
L
1

I ended up having to customize the TURNSocket class to meet my specific needs to be able to transfer a file from my iOS device to another device. If there is a proxy server available, then the TURNSocket class might work for one's needs. But if this is a direct connection where a proxy server may not be available, then some extra work is necessary to set up your device to be able to connect to another device and directly transfer a file.

I was able to receive a file using TURNSocket in its current form with only one minor modification. As the code currently stands, the id and sid are assigned the same value, which cannot be guaranteed that a received stanza will have the same unique identifier value for both the id and sid.

Literatim answered 15/11, 2011 at 16:26 Comment(3)
edenwaith, could you please share how you are able to transfer files using TurnSocket. I am getting 'socket did fail' all the time.Triclinium
@Literatim could you please share how you are able to transfer files using TurnSocket. I am getting 'socket did fail' all the timeEuratom
Sorry, I no longer have access to the original code so I cannot share any of it.Literatim
S
0

You should have use xep-96 to make it possible to share and receive files. after that just initiate xmppSifiletranfer with relevant data. like

-(void)sendToOtherDevice:(NSData *)fileData receiverJid:(XmPPJId *)senderFullID file:(NSString *)fileName{

            myFileTransferID=[xmppStream generateUUID];
            XMPPJID *jid =senderFullID;
            sifiletransfer=[[XMPPSIFileTransfer alloc]init];
            [sifiletransfer initiateFileTransferTo:jid withData:fileData file:fileName passedsid:myFileTransferID];

            if ([jid.domain isEqualToString:[xmppStream myJID].domain]) {
                [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain, nil]];
            } else {
                [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain,[xmppStream myJID].domain, nil]];
            }
             TURNSocket *socket = [[TURNSocket alloc] initWithStream:xmppStream toJID:jid sid:myFileTransferID];
           // [socket setDataToSend:fileData];

            [socket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
    }
    # delegater of turnsocket
    - (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket
    {
        NSLog(@"Socket Suceeed Port For File Transfer: %d",socket.localPort);
        DDLogInfo(@"TURN Connection succeeded!");
        DDLogInfo(@"You now have a socket that you can use to send/receive data to/from the other person.");
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hurray!!"
         message:@"Conection Established"
         delegate:nil
         cancelButtonTitle:@"Ok"
         otherButtonTitles:nil];
         [alertView show];
    }

if you guys have any other issue regarding file transfer comment below.I will surely help you.
Sotelo answered 20/9, 2014 at 7:3 Comment(7)
I am getting following error <iq xmlns="jabber:client" type="error" id="797190C9-89F8-4D15-8DF6-90B8C4CE40AF" from="[email protected]" to="[email protected]/173bf5c2"><query xmlns="jabber.org/protocol/bytestreams" sid="797190C9-89F8-4D15-8DF6-90B8C4CE40AF" mode="tcp"><streamhost jid="proxy.192.168.2.120" host="192.168.2.120" port="7777"/></query><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>. Can you please help me? What can be the real issue?Ithunn
looks like somewhere you missing some stanza.Have you properly configure XMPPSIFileTransfer file ?Sotelo
I am not sure for configuration for XMPPSIFileTransfer file. Can you please tell me which configuration I need to do for XMPPSIFileTransfer file? I have set xmpp.proxy.externalip which is my domain name for Open fire server is it ok?Ithunn
do you have xep-96 folder in your xmpp package.If yes ! just open it you will find XMPPSIFileTranfer file.Then look at delegate methods declare in it.Sotelo
I have both XMPPSIFileTranfer files in xep-96 folder in my app. I have implemented delegate methods also in my AppDelegate. Can you please look up at my question. #26251033 It would be very helpful. I am stuck since last two days so. :(Ithunn
Hey! Jayesh .Just go on your question.Your mistake is identified.Just use JID in correct format as i commented on your question.Sotelo
XMPPSIFileTransfer doesn't exist in latest iOS XMPP Framework. You should edit your answer and give the accurate answer.Schwenk

© 2022 - 2024 — McMap. All rights reserved.