无法使用asmack传输文件

时间:2013-11-25 11:15:01

标签: android xmpp file-transfer smack asmack

我创建了一个聊天应用程序,我正在使用asmack lib。 我正在尝试在同一个XMPP服务器上的两个客户端(Android应用程序)之间传输文件,但是我得到了一个奇怪的错误。

当我尝试发送文件时,传出文件传输开始,目标客户端收到请求,但源客户端无法进一步进行传输协商。我总是陷入'谈判转移'......

通过从移动应用程序向桌面应用程序(例如Spark IM Client)发送文件,只能成功传输文件。

知道造成这种情况的原因是什么?

发送文件:

OutgoingFileTransfer lTransfer = mFileTransferManager.createOutgoingFileTransfer(mJid+"/"+resource);
// Send the file
try {
    lTransfer.sendFile(new File(filePath),mMessage);
    } catch (XMPPException e) {
    Log.e(TAG,"Error sending file");
}

while(!lTransfer.isDone()){
    if(lTransfer.getStatus().equals(FileTransfer.Status.error)) {
        Log.e(TAG,"ERROR!!! " + lTransfer.getError());
        } else {
        Log.i(TAG, "Status:"+lTransfer.getStatus().toString());
        Log.i(TAG, "Progress:"+String.valueOf(lTransfer.getProgress()));
    }
    try {
        Thread.sleep(1000);
} catch (InterruptedException ignored) { }
}

if(lTransfer.getStatus().equals(FileTransfer.Status.refused)
|| lTransfer.getStatus().equals(FileTransfer.Status.error)
|| lTransfer.getStatus().equals(FileTransfer.Status.cancelled)){
    Log.e(TAG,"refused cancelled error " + lTransfer.getError());
    return false;
    } else {
    Log.i(TAG,"Sucesss");
    return true;
}

收到档案:

mFileTransferManager.addFileTransferListener(new FileTransferListener() {
    public void fileTransferRequest(FileTransferRequest request) {
        String path = "/sdcard/"+ request.getFileName();
        IncomingFileTransfer lTransfer = fileTransferRequest.accept();
        lTransfer.recieveFile(new File(path));
        double percents = 0.0;
        while (!lTransfer.isDone()) {
            if (lTransfer.getStatus().equals(FileTransfer.Status.in_progress)) {
                percents = ((int) (lTransfer.getProgress() * 10000)) / 100.0;
                Log.d(TAG, "File transfer: " + newFile.getAbsolutePath() + " - " + percents + "%");
                } else if (lTransfer.getStatus().equals(FileTransfer.Status.error)) {
                Log.e(TAG, "ERROR in transfer");
                return;
            }
            Thread.sleep(1000);
        }
        if (lTransfer.getStatus().equals(FileTransfer.Status.complete)) {
            Log.i(TAG, "File transfert: " + newFile.getAbsolutePath() + " - 100%");
            } else {
            Log.e(TAG, "ERROR in transfer");
        }
    });

ProviderManager configure

ProviderManager pm = ProviderManager.getInstance();
 //  Private Data Storage
        pm.addIQProvider("query","jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
        //  Time
        try {
            pm.addIQProvider("query","jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
        } catch (ClassNotFoundException e) {
            QuickLogger.w("Can't load class for org.jivesoftware.smackx.packet.Time");
        }

        //  XHTML
        pm.addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());

        //  Roster Exchange
        pm.addExtensionProvider("x","jabber:x:roster", new RosterExchangeProvider());
        //  Message Events
        pm.addExtensionProvider("x","jabber:x:event", new MessageEventProvider());
        //  Chat State
        pm.addExtensionProvider("active","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
        pm.addExtensionProvider("composing","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
        pm.addExtensionProvider("paused","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
        pm.addExtensionProvider("inactive","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
        pm.addExtensionProvider("gone","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());

        //   FileTransfer
        pm.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
        pm.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
        pm.addIQProvider("open","http://jabber.org/protocol/ibb", new OpenIQProvider());
        pm.addIQProvider("close","http://jabber.org/protocol/ibb", new CloseIQProvider());
        pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider());

        //  Group Chat Invitations
        pm.addExtensionProvider("x","jabber:x:conference", new GroupChatInvitation.Provider());
        //  Service Discovery # Items
        pm.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
        //  Service Discovery # Info
        pm.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
        //  Data Forms
        pm.addExtensionProvider("x","jabber:x:data", new DataFormProvider());
        //  MUC User
        pm.addExtensionProvider("x","http://jabber.org/protocol/muc#user", new MUCUserProvider());
        //  MUC Admin
        pm.addIQProvider("query","http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
        //  MUC Owner
        pm.addIQProvider("query","http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
        //  Delayed Delivery
        pm.addExtensionProvider("x","jabber:x:delay", new DelayInformationProvider());
        //  Version
        try {
            pm.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
        } catch (ClassNotFoundException e) {
            QuickLogger.w("Can't load class for org.jivesoftware.smackx.packet.Version");
        }
        //  VCard
        pm.addIQProvider("vCard","vcard-temp", new VCardProvider());
        //  Offline Message Requests
        pm.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
        //  Offline Message Indicator
        pm.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
        //  Last Activity
        pm.addIQProvider("query","jabber:iq:last", new LastActivity.Provider());
        //  User Search
        pm.addIQProvider("query","jabber:iq:search", new UserSearch.Provider());
        //  SharedGroupsInfo
        pm.addIQProvider("sharedgroup","http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
        //  JEP-33: Extended Stanza Addressing
        pm.addExtensionProvider("addresses","http://jabber.org/protocol/address", new MultipleAddressesProvider());

0 个答案:

没有答案