Receiving a file doesn't work in Smack3.2.1

  1. send a file:

// Create the file transfer manager

FileTransferManager manager = new FileTransferManager(connection);

// Create the outgoing file transfer

FileTransferNegotiator.setServiceEnabled(connection, true);

OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(jID);

// Send the file

transfer.sendFile(file, message);

while (!transfer.isDone()) {

EIPLogger.debug(transfer.getProgress() + " is done!");

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

EIPLogger.error("", e);

}

}

  1. receive the file:

// Create the file transfer manager

FileTransferNegotiator.setServiceEnabled(connection, true);

final FileTransferManager manager = new FileTransferManager(connection);

// Create the listener

manager.addFileTransferListener(new FileTransferListener() {

public void fileTransferRequest(FileTransferRequest request) {

// Accept it

try {

if(request.getFileName().endsWith(“bmp”))

request.reject();

IncomingFileTransfer transfer = request.accept();

System.out.println(“File received:”+request.getFileName());

transfer.recieveFile(new File(request.getFileName()));

while(!transfer.isDone())

{

System.out.println(“receiving the file…”);

if(transfer.getStatus().equals(Status.error)) {

System.out.println("ERROR!!! " + transfer.getError());

} else {

System.out.println(transfer.getStatus());

System.out.println(transfer.getProgress());

}

Thread.currentThread().sleep(1000);

}

System.out.println(“File Received”);

} catch (Exception e) {

e.printStackTrace();

}

}

});

  1. Output log:

receiving the file…

Initial

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

receiving the file…

Negotiating Stream

0.0

File Received

But the file i received is always 0kb, anyone who can explain what’s wrong with above codes?thanks a lot.

3.2.1 defaults to using IQs to deliver inband data for file transfers. Transfers will fail unless both clients are able to support using IQs vice Message packets. You can change from the default use of IQs:

InBandBytestreamManager.getByteStreamManager(connection).setStanza(StanzaType.ME SSAGE);

Keith, do you know if IBB with Message packets work flawlessly with Smack 3.2.1? We are trying to fix Spark 2.6.3 and it’s IBB trouble. Any information is highly appreciated.