powered by Jive Software

File Transfer is not working

Hello Friend,

public void SendFile(String Receiver, final String Directory)

{

Presence presence = g.connection.getRoster().getPresence(Receiver);

System.out.println(“username:”+Receiver);

if(presence.getType() == Presence.Type.available)

{

Receiver = presence.getFrom();

}

ServiceDiscoveryManager sdm = ServiceDiscoveryManager

.getInstanceFor(g.connection);

if (sdm == null)

sdm = new ServiceDiscoveryManager(g.connection);

                                      sdm.addFeature("[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)");

                                      sdm.addFeature("[http://jabber.org/protocol/disco#item](http://jabber.org/protocol/disco#item)");

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

//connConfig.setPacketReplyTimeout(15000);

// FileTransferNegotiator.IBB_ONLY = true;

FileTransferManager manager = new FileTransferManager(g.connection);

FileTransferNegotiator

.setServiceEnabled(g.connection, true);

OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(Receiver);

File file = new File(Directory);

try {

transfer.sendFile(file, “test_file”);

} catch (XMPPException e) {

e.printStackTrace();

}

while(!transfer.isDone()) {

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

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

} else if (transfer.getStatus().equals(Status.cancelled)

|| transfer.getStatus().equals(Status.refused)) {

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

}

try {

Thread.sleep(1000L);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

if(transfer.getStatus().equals(Status.refused) || transfer.getStatus().equals(Status.error)

|| transfer.getStatus().equals(Status.cancelled)){

System.out.println("refused cancelled error " + transfer.getError());

} else {

System.out.println(“Success”);

}

}

this is my file transfer code, when i run it it will send request to user and when user accept request file transfer start and stop automatically.

I don’t the reason. plz help me.

Thanks in advance