Hi Hi,
I am making an xmpp chat program. Now I am adding a feature to send and receive files. Please refer to this post: http://www.igniterealtime.org/community/thread/39080?tstart=0
That problem was fixed, but now I got another problem.
User A, and B are both connected to the gtalk server using my program, and A is sending the file to B.
If the file from A is under 60KB, B received the file correctly. However, if the file from A is over 60KB, no matter how big it is,
it will end up a 60KB file in B. But the transfer was there, I used while(!transfer.isDone()) to check the transfer.progress(), and bigger file needed longer time to transfer.
Does anyone know why B can’t receiver the file over 60KB but the prograss was actually transfered over 60KB…?
Is it the problem with the gtalk server? (Is the file transfer p2p not going through the server?)
Is there any way to fix it?
Thanks in advance.
Here is my code to test send and receive file:
Sender:
public class SendTest {
public static void main( String[] args ) {
XMPPConnection.DEBUG_ENABLED = true;
System.out.println("Starting IM client");
// gtalk requires this or your messages bounce back as errors
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
System.out.println("Connected to " + connection.getHost());
} catch (XMPPException ex) {
//ex.printStackTrace();
System.out.println("Failed to connect to " + connection.getHost());
System.exit(1);
}
try {
connection.login("abc@gmail.com", "abc");
System.out.println("Logged in as " + connection.getUser()); } catch (XMPPException ex) {
//ex.printStackTrace();
System.out.println("Failed to log in as " + connection.getUser());
System.exit(1);
}
// Create the file transfer manager
FileTransferManager manager = new FileTransferManager(connection);
// Create the outgoing file transfer
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("abcdef@gmail.com/SmackBD1EB625");
// Send the file
try {
transfer.sendFile(new File("11MBFile.exe"), "You won't believe this!");
while(!transfer.isDone())
{
System.out.println(transfer.getProgress() + " 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();
} System.out.println("Press enter to disconnect");
try {
System.in.read();
} catch (IOException ex) {
//ex.printStackTrace();
}
connection.disconnect(); }
Receiver:
public class ReceiveTest {
public static void main( String[] args ) {
XMPPConnection.DEBUG_ENABLED = true;
System.out.println("Starting IM client");
// gtalk requires this or your messages bounce back as errors
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
System.out.println("Connected to " + connection.getHost());
} catch (XMPPException ex) {
//ex.printStackTrace();
System.out.println("Failed to connect to " + connection.getHost());
System.exit(1);
}
try {
connection.login("abcdef@gmail.com", "abcdef");
System.out.println("Logged in as " + connection.getUser());
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
} catch (XMPPException ex) {
//ex.printStackTrace();
System.out.println("Failed to log in as " + connection.getUser());
System.exit(1);
}
// Create the file transfer manager
final FileTransferManager manager = new FileTransferManager(connection); // Create the listener
manager.addFileTransferListener(new FileTransferListener() {
public void fileTransferRequest(FileTransferRequest request) {
// Accept it
try {
IncomingFileTransfer transfer = request.accept();
transfer.recieveFile(new File("11MBFile.exe"));
System.out.println("File Received");
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}); System.out.println("Press enter to disconnect");
try {
System.in.read();
} catch (IOException ex) {
//ex.printStackTrace();
}
connection.disconnect(); }
}