Skip navigation
5940 Views 7 Replies Latest reply: Sep 7, 2009 10:16 AM by Win Myo Htet RSS
kouami Bronze 5 posts since
Mar 5, 2009
Currently Being Moderated

Mar 7, 2009 10:33 AM

File Transfer with Smack Not Working

Hi,

I am using the code below for File Transfer with the Smack api but for some reason I am not seeing the file being transfered at all. In my driver program when I check the status of the transfer, it is always in "Negotiating Transfer" state. However, in the smack debugger it is showing that the file is sent from client A to B and Client B received it. I don't know what is going on. I am using smack and openfire. I also made sure that File transfer is enable on the server(Openfire)

Plz help me solve this.

Thanks,

 

Emmanuel

 

public void fileTransfer(String fileName, String destination) throws XMPPException {

        // Create the file transfer manager
        FileTransferManager manager = new FileTransferManager(connection);

        FileTransferNegotiator.setServiceEnabled(connection, true);
        // Create the outgoing file transfer
        OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(destination);
        // Send the file
        transfer.sendFile(new File(fileName), "You won't believe this!");
      
       
        while (!transfer.isDone()) {
            if (transfer.getStatus().equals(Status.error)) {
                System.out.println("ERROR!!! " + transfer.getError());
            } else {
                System.out.println(transfer.getStatus());
                System.out.println(transfer.getProgress());
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(SimpleSmackClient.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

    public void fileReceiver(final boolean accept, final String fileName) {
        // Create the file transfer manager
        final FileTransferManager manager = new FileTransferManager(connection);

        // Create the listener
        manager.addFileTransferListener(new FileTransferListener() {

            public void fileTransferRequest(FileTransferRequest request) {
               
                // Check to see if the request should be accepted
                if (accept) {
                    // Accept it
                    IncomingFileTransfer transfer = request.accept();
                    try {
                        transfer.recieveFile(new File(fileName));
                    } catch (XMPPException ex) {
                        ex.printStackTrace();
                    }
                } else {
                    // Reject it
                    request.reject();
                }
            }
        });
    }

    • drd6y Bronze 1 posts since
      Apr 2, 2009
      Currently Being Moderated
      Apr 2, 2009 4:32 PM (in response to kouami)
      Re: File Transfer with Smack Not Working

      i am having the same problem what did you do to resolve the issue?!!!??

          • skymedichen Bronze 1 posts since
            Jun 29, 2009
            Currently Being Moderated
            Jun 29, 2009 1:51 AM (in response to kouami)
            Re: File Transfer with Smack Not Working

            Hi Kouami,

             

            I am using Smack in Android. I have successfully tansferied message but not the file.

             

             

            I get the NullPointerException in:   FileTransferNegotiator.setServiceEnabled(connection,true);

             

            I am using Android SDk1.5 and the Smack jar is gotten from http://davanum.wordpress.com/2008/12/29/updated-xmpp-client-for-android/#comment -2279.

             

             

            Thanks in advance.

             

            Ethan

            • Win Myo Htet Silver 333 posts since
              Aug 4, 2005
              Currently Being Moderated
              Sep 3, 2009 8:06 PM (in response to skymedichen)
              Re: File Transfer with Smack Not Working

              skymedichen,

               

              If you are trying to get file transfer working on Android, you need to read the following thread. Because working for android environment is not the same as working for standard java.

               

              http://www.igniterealtime.org/community/message/195679#195679

              • Win Myo Htet Silver 333 posts since
                Aug 4, 2005
                Currently Being Moderated
                Sep 7, 2009 10:16 AM (in response to Win Myo Htet)
                Smack File Transfer is not ready for prime time?

                I think, that smack file transfer is not ready for prime time yet cause I am having issue testing out spark which should be the best implementation of smack.

                 

                http://www.igniterealtime.org/community/thread/39665?tstart=0

                 

                At first, I thought that 60kb limitation might be triggered by google because they are known not to be xmpp compliant. However I don't find  the 60kb limitation problem when I test out the very basic file transfer implementation (using the example code) between my two android apps using google accounts. I can send file of size 3MB successfully most of the time in a control environment (which is both clients have the same connection speed). I could never send 30MB size tho. I have only tested with these 2 sizes in a control environment.

                 

                File transfer cannot transfer file size less than 0.5MB (well 443KB) while the two clients have different connection speeds (DSL to modem or 3G to Edge scenario) when it is from very fast connection speed to the slow connection speed. The fast client will get 503 error and will stop transferring after 200kb. I don't know if I have to deal with the connection speed myself manually.

                 

                I feel disappointed that spark file transfer does not even work out of the box for me in the first place.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points