powered by Jive Software

Smack File Transfer Problem Again

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();      }
}

Here is the output:

Sender A:

Starting IM client
Connected to talk.google.com
Logged in as abc@gmail.com/Smack171DAF0E
0.0 is done!
0.0 is done!
0.003355225304689845 is done!
0.00603940554844172 is done!
0.009394630853131565 is done!
0.01207881109688344 is done!
0.015434036401573287 is done!
0.01878926170626313 is done!
0.021473441950015007 is done!
0.024828667254704853 is done!
0.028183892559394696 is done!
0.030868072803146573 is done!
0.03422329810783642 is done!
0.036907478351588294 is done!
0.04026270365627814 is done!
0.04361792896096798 is done!
0.04630210920471986 is done!
0.049657334509409706 is done!
0.05234151475316158 is done!
0.05569674005785143 is done!
0.059051965362541266 is done!
0.06173614560629315 is done!
0.06509137091098299 is done!
0.06777555115473487 is done!
0.07113077645942471 is done!
0.07448600176411456 is done!
0.07717018200786643 is done!
0.08052540731255628 is done!
0.08320958755630815 is done!
0.086564812860998 is done!
0.08992003816568785 is done!
0.09260421840943972 is done!

Receiver B:

Starting IM client
Connected to talk.google.com
Logged in as abcdef@gmail.com/SmackC96F640A
Press enter to disconnect
0.0 is done!
0.0010065675914069535 is done!
0.004026270365627814 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
0.0050328379570347675 is done!
Receiver B will stop receiving after 0.0050 is done (60KB) is received, but Sender A is keep sending the file. Does anybody know why B can’t receiver the whole file?

Thank you.