DataSmith
DataSmith

Reputation: 11

How to send files using Smack?

I am struggling with this code:

FileTransferManager manager = new FileTransferManager(connection)

OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("gmailusername@gmail/Smack");


try { 
  System.out.println("000"); 
  transfer.sendFile(new File("D:/cow.wav"), "Moo !"); 
  System.out.println("111"); 

  while(!transfer.isDone()) { 
    System.out.println(transfer.getProgress() + " is done!");    
    //System.out.println(transfer.getStreamID() + " is done!"); 

    try { 
      Thread.sleep(1000); 
    } 
    catch (InterruptedException e) { 
      // TODO Auto-generated catch block e.printStackTrace(); 
    }
  } 
} 
catch (XMPPException e) { 
  // TODO Auto-generated catch block e.printStackTrace(); 
}

It seams that it can't send the file.

Can anyone help me solve this problem ?

Upvotes: 0

Views: 2999

Answers (3)

Jindal
Jindal

Reputation: 1

You haven't entered the complete id of receiver. Retrieve it using

myRoster.getRoster().getPresence(entry).getFrom()

Then, make the transfer and ensure that recieiver is the one using XMPP and also doesn't use gtalk because its file transfer is different from XMPP.

Upvotes: 0

nick
nick

Reputation: 1075

We discovered that SMACK tends to add the "/smack" application specifier after login. If you use the above techniques you should see this happening. Oddly this doesn't affect messages but does affect file transfer

Upvotes: 0

Chuk Lee
Chuk Lee

Reputation: 3608

I believe Gmail (judging from your code above) does not support file transfer. See this. You can also send a disco#item and disco#info to see if it supports any kind of byte stream proxy. However some servers like jabber.org does not return any disco#info on proxies.

For querying XMPP services see my blog.

Upvotes: 2

Related Questions