powered by Jive Software

Problem sending files

I am using a test program to send file to Spark client but i get the following error on the debug window from my test program:

Debug:

Sent:

test filehttp://jabber.org/protocol/bytestreamshttp://jabber.org/protocol/ibb

receive:

test filehttp://jabber.org/protocol/bytestreamshttp://jabber.org/protocol/ibb

I can chat fine with the client but when sending file the client doesn’t even receive an incoming file transfer notice!

Here is my code for sending file:

public void sendFile(String to) {

    File file = new File("Firefox_wallpaper.png");
   
    if (file != null) {
        FileTransferManager fileXferManager;
        fileXferManager = new FileTransferManager(connection);
        fileXferManager.addFileTransferListener(this);

if (fileXferManager != null) {
OutgoingFileTransfer transfer = fileXferManager.createOutgoingFileTransfer(to);
OutgoingFileTransfer.setResponseTimeout(60000);
try {
transfer.sendFile(file,“test file”);
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

        }
    }
}

Connection info:

ConnectionConfiguration config = new ConnectionConfiguration(“openfire”,5222, “openfire”);
connection = new XMPPConnection(config);
connection.connect();
connection.login(“test1”, “password”);

do i need to send to a different port or have some sort of transaction before send? i am a bit stuck… thanks!

Hi,

The problem might be that you didn’t use a fully-qualified user ID as the intended destination. I made that mistake myself when I first implemented file transfers. I can see in your “sent” debug packet that the “to” field was set to “test2@openfire”, which does not include a resource such as “/Smack” like the “from” field. File transfers require the resource portion of the user ID so that if the user is logged in multiple times (ie Home, Work, etc.), it knows where to send the file. This is actually documented in the JavaDoc for the FileTransferManager#createOutgoingFileTransfer method parameters, but it is easy to miss.

Now the next question is how do you figure out the correct resource for the user ID that you should use?

This can be achieved using the Roster#getPresences method, which will give you all the presence packets the user is currently connected with. Then you can loop through each presence packet and make sure that it 1.) has a resource and 2.) has the highest priority using the Presence#getPriority method. Once you have identified the most appropriate presence packet, you can use the Presence#getFrom method to get the actual user ID that should be passed to the file transfer manager.