powered by Jive Software

File transfer issue using smack 3.2.1

Hi all,

I am trying to send and recieve the file using smack and open fire 3.9.2. when I try to sending the file it done successfully but at the recievers end it creates the file with 0kb and showing progress 0.0 till infinite time.

On smack debugging It shows the recived data, but not updating the file.

Following is the code that i am using.

public void sendFile(final String Directory, final String Receiver) {

// ProviderManager.getInstance().addIQProvider(“query”, “http://jabber.org/protocol/bytestreams”, new BytestreamsProvider());

// ProviderManager.getInstance().addIQProvider(“query”, “http://jabber.org/protocol/disco#items”, new DiscoverItemsProvider());

// ProviderManager.getInstance().addIQProvider(“query”, “http://jabber.org/protocol/disco#info”, new DiscoverInfoProvider());

// ProviderManager.getInstance().addIQProvider(“si”, “http://jabber.org/protocol/si”, new StreamInitiationProvider());

// ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);

// if (sdm == null) {

// sdm = new ServiceDiscoveryManager(connection);

// }

// sdm.addFeature(“http://jabber.org/protocol/disco#info”);

// sdm.addFeature(“http://jabber.org/protocol/disco#item”);

// sdm.addFeature(“jabber:iq:privacy”);

// Create the file transfer manager

FileTransferManager manager = new FileTransferManager(

connection);

// FileTransferNegotiator.setServiceEnabled(connection, true);

// // Create the outgoing file transfer

// FileTransferNegotiator.IBB_ONLY = true;

OutgoingFileTransfer transfer = manager

.createOutgoingFileTransfer(Receiver + “/Smack”);

InBandBytestreamManager.getByteStreamManager(connection).setStanza(InBandBytestr eamManager.StanzaType.MESSAGE);

System.out.println(“transfere file : outgoingfiletransfere is created”);

try {

OutgoingFileTransfer.setResponseTimeout(30000);

transfer.sendFile(new File(Directory), “Description”);

System.out.println(“transfere file : sending file”);

while (!transfer.isDone()) {

try {

Thread.sleep(1000);

System.out.println("transfere file : sending file "

  • transfer.getStatus() + " progress: "

  • transfer.getProgress());

if (transfer.getStatus() == FileTransfer.Status.error) {

transfer.cancel();

break;

}

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.println(“transfere file : sending file done”);

}

public void receiveFile() {

// ProviderManager.getInstance().addIQProvider(“query”, “http://jabber.org/protocol/bytestreams”, new BytestreamsProvider());

// ProviderManager.getInstance().addIQProvider(“query”, “http://jabber.org/protocol/disco#items”, new DiscoverItemsProvider());

// ProviderManager.getInstance().addIQProvider(“query”, “http://jabber.org/protocol/disco#info”, new DiscoverInfoProvider());

// ProviderManager.getInstance().addIQProvider(“si”, “http://jabber.org/protocol/si”, new StreamInitiationProvider());

// ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);

// if (sdm == null) {

// sdm = new ServiceDiscoveryManager(connection);

// }

// sdm.addFeature(“http://jabber.org/protocol/disco#info”);

// sdm.addFeature(“http://jabber.org/protocol/disco#item”);

// sdm.addFeature(“jabber:iq:privacy”);

// Create the file transfer manager

InBandBytestreamManager.getByteStreamManager(connection).setStanza(InBandBytest reamManager.StanzaType.MESSAGE);

final FileTransferManager managerListner = new FileTransferManager(connection);

FileTransferNegotiator.setServiceEnabled(connection, true);

// FileTransferNegotiator.IBB_ONLY = true;

System.out.println(“File transfere manager,created”);

// Create the listener

managerListner.addFileTransferListener(new FileTransferListener() {

public void fileTransferRequest(final FileTransferRequest request) {

System.out.println(“Recieve File,new file transfere request new file transfere request new file transfere request”);

System.out.println("file request from " + request.getRequestor());

IncomingFileTransfer transfer = request.accept();

System.out.println(“Recieve File alert dialog,accepted”);

try {

transfer.recieveFile(new File(dir + “\” + request.getFileName()));

while (!transfer.isDone()/* && (transfer.getProgress() < 1)*/) {

Thread.sleep(1000);

System.out.println("Recieve File alert dialog,still receiving : " + (transfer.getProgress()) + " status " + transfer.getStatus());

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

// Log.i(“Error file”,

// transfer.getError().getMessage());

System.out.println("Recieve File alert dialog,cancelling still receiving : " + (transfer.getProgress()) + " status " + transfer.getStatus());

transfer.cancel();

break;

}

}

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

}

Please help me on the same.

Hi.
I also have same issue.

Was you able to found solution?