3

「Android チャット」から他のクライアント (Pidgin など) へのファイル転送の処理に問題があります。Pidgin クライアントは転送要求を受け取りますが、アプリケーションはファイルの転送を開始できません。

すべての stackoverflows の質問、いくつかのhttp://community.igniterealtime.org/スレッドを読んだと言わざるを得ませんが、それでも私の問題は解決しませんでした。

テストするために、ポート 5222 で jabber.org サーバーを使用しており、Beem-Asmack ライブラリ v7 を使用しています (一部のクライアントでは、プロキシも指定する必要があります: これは必要ですか??)。ファイル転送のコードは次のとおりです。

public boolean sendFile(final String jid, final String path, String description) {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(this.xmpp);
    /*if (sdm==null) {
        sdm = new ServiceDiscoveryManager(this.xmpp);*/
        sdm.addFeature("http://jabber.org/protocol/disco#info");
        sdm.addFeature("http://jabber.org/protocol/disco#item");
        sdm.addFeature("jabber:iq:privacy");
    //}

    Log.d("sending file", "maganer");
    FileTransferNegotiator.setServiceEnabled(this.xmpp, true);
    FileTransferManager manage = new FileTransferManager(this.xmpp);
    Log.d("sending file", "set true");

    OutgoingFileTransfer.setResponseTimeout(10000);
    OutgoingFileTransfer oft = manage.createOutgoingFileTransfer(this.myRoster.getPresence(jid).getFrom());
    try {
        Log.d("sending file", "try to send... " + path);
        oft.sendFile(new File(path), description);
        Log.d("sending file", "Accepted");
        while (!oft.isDone()) {
            Log.d("status", oft.getStatus().toString());
            Log.d("percent", new Long(oft.getBytesSent()).toString());
            if (oft.getStatus() == FileTransfer.Status.error) {
                Log.e("percent", "Error " + new Long(oft.getBytesSent()).toString() + " " + oft.getError() + " " + oft.getException());
                oft.cancel();
                return false;
            }
            //Thread.sleep(1000);
        }
    } catch (Throwable e) {
        e.printStackTrace();
        Log.e("sendFile", path);
        return false;
    }
    return true;
}

リモートサービスの作成時に次の手順も実行しています

private void startup() {
    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) {
        Log.w("TestClient",
            "Can't load class for org.jivesoftware.smackx.packet.Time");
    }

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

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

    // 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) {
        // Not sure what's happening here.
    }

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

    // 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 IBBProviders.Open());
    //
    pm.addIQProvider("close","http://jabber.org/protocol/ibb",
        new IBBProviders.Close());
    //
    pm.addExtensionProvider("data","http://jabber.org/protocol/ibb",
        new IBBProviders.Data());

    //
    pm.addExtensionProvider("x","jabber:x:data", new DataFormProvider());

    // Privacy
    pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());

    pm.addIQProvider("command", "http://jabber.org/protocol/commands",
        new AdHocCommandDataProvider());
    pm.addExtensionProvider("malformed-action",
        "http://jabber.org/protocol/commands",
        new AdHocCommandDataProvider.MalformedActionError());
    pm.addExtensionProvider("bad-locale",
        "http://jabber.org/protocol/commands",
        new AdHocCommandDataProvider.BadLocaleError());
    pm.addExtensionProvider("bad-payload",
        "http://jabber.org/protocol/commands",
        new AdHocCommandDataProvider.BadPayloadError());
    pm.addExtensionProvider("bad-sessionid",
        "http://jabber.org/protocol/commands",
        new AdHocCommandDataProvider.BadSessionIDError());
    pm.addExtensionProvider("session-expired",
        "http://jabber.org/protocol/commands",
        new AdHocCommandDataProvider.SessionExpiredError());

    //  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) {
        Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time");
    }

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

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

    //  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) {
        //  Not sure what's happening here.
    }

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

    //   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 IBBProviders.Open());

    pm.addIQProvider("close", "http://jabber.org/protocol/ibb", new IBBProviders.Close());

    pm.addExtensionProvider("data", "http://jabber.org/protocol/ibb", new IBBProviders.Data());

    //  Privacy
    pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());

    pm.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
    pm.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
    pm.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
    pm.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
    pm.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
    pm.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
}

次に、エラーについて説明します。ロギングから、「パーセント」として -1 を受け取り、「ステータス」として「ネゴシエーション ストリーム」を受け取ります。どこが間違っているのか、転送を開始する方法がわかりません。アドバイスや提案をありがとう。

編集(2) 今、追加することで問題を部分的に解決しました

FileTransferNegotiator.IBB_ONLY = true;

FileTransferManager を初期化し、ServiceDiscoveryManager の初期化を次のように再配置する前に、次のようにします。

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(this.xmpp);
     if (sdm==null)
         sdm = new ServiceDiscoveryManager(this.xmpp);
     sdm.addFeature("http://jabber.org/protocol/disco#info");
     sdm.addFeature("http://jabber.org/protocol/disco#item");
     sdm.addFeature("jabber:iq:privacy");

また、起動時に次の構成を追加しました。

SmackConfiguration.setPacketReplyTimeout(15000);

ちなみに、今は元のファイルと同じ量の進行値に達していますが、ファイルは受信側で閉じられていません。その結果、タイムアウトが発生し、転送が中止されます。ファイルのファイナライズをどのように伝えることができますか? 他のクライアント(Pidgin)が処理しない場合でも、ファイル全体を転送しているようです。よろしくお願いします。

4

1 に答える 1

1
public void send()
{

    configureProviderManager(connection);
    FileTransferNegotiator.IBB_ONLY = true;
    FileTransferNegotiator.setServiceEnabled(connection, true);
    FileTransferManager manager = new FileTransferManager(connection);
    //OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("hariom@jabber.ccc.de/Smack");
    String to = connection.getRoster().getPresence("hariom@jabber.ccc.de").getFrom();
    OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(to);


    File file = new File("/sdcard/DCIM/Camera/1385869353956.jpg");
    try {
        Log.d("file sending",file.getAbsolutePath()+" "+file.getName());
        configureProviderManager(connection);
       transfer.sendFile(file, "test_file");
    } catch (XMPPException e) {
       e.printStackTrace();
    }

    while(!transfer.isDone()) {
        Log.d("status", transfer.getStatus().toString());
        Log.d("percent", new Long(transfer.getBytesSent()).toString());
        if (transfer.getStatus() == Status.error) {
            Log.e("percent", "Error " + new Long(transfer.getBytesSent()).toString() + " " + transfer.getError() + " " + transfer.getException());
            transfer.cancel();

        }

        if(transfer.getStatus().equals(Status.refused))
                 System.out.println("refused  " + transfer.getError());
        else if( transfer.getStatus().equals(Status.error))
             System.out.println(" error " + transfer.getError());
        else if(transfer.getStatus().equals(Status.cancelled))
           System.out.println(" cancelled  " + transfer.getError());
        else
           System.out.println("Success");



    }
}



public void configureProviderManager(XMPPConnection connection) {


    ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
    ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
    ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());



    ProviderManager.getInstance().addIQProvider("query",
            "http://jabber.org/protocol/bytestreams",
            new BytestreamsProvider());
    ProviderManager.getInstance().addIQProvider("query",
            "http://jabber.org/protocol/disco#items",
            new DiscoverItemsProvider());
    ProviderManager.getInstance().addIQProvider("query",
            "http://jabber.org/protocol/disco#info",
            new DiscoverInfoProvider());

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    if (sdm == null)
        sdm = new ServiceDiscoveryManager(connection);

    sdm.addFeature("http://jabber.org/protocol/disco#info");
    sdm.addFeature("http://jabber.org/protocol/disco#item");
    sdm.addFeature("jabber:iq:privacy");


    ProviderManager pm = ProviderManager.getInstance();

    // The order is the same as in the smack.providers file

    //  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) {
        System.err.println("Can't load class for org.jivesoftware.smackx.packet.Time");
    }

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

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

    //  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());
    pm.addExtensionProvider("delay", "urn:xmpp:delay", new DelayInformationProvider());
    //  Version
    try {
        pm.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
    } catch (ClassNotFoundException e) {
        System.err.println("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());

    //   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("data","http://jabber.org/protocol/ibb", new DataPacketProvider());
    pm.addIQProvider("close","http://jabber.org/protocol/ibb", new CloseIQProvider());
    pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider());

    //  Privacy
    pm.addIQProvider("query","jabber:iq:privacy", new PrivacyProvider());

    // SHIM
    pm.addExtensionProvider("headers", "http://jabber.org/protocol/shim", new HeadersProvider());
    pm.addExtensionProvider("header", "http://jabber.org/protocol/shim", new HeaderProvider());

    // PubSub
    pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider());
    pm.addExtensionProvider("create", "http://jabber.org/protocol/pubsub", new SimpleNodeProvider());
    pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider());
    pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub", new ItemProvider());
    pm.addExtensionProvider("subscriptions", "http://jabber.org/protocol/pubsub", new SubscriptionsProvider());
    pm.addExtensionProvider("subscription", "http://jabber.org/protocol/pubsub", new SubscriptionProvider());
    pm.addExtensionProvider("affiliations", "http://jabber.org/protocol/pubsub", new AffiliationsProvider());
    pm.addExtensionProvider("affiliation", "http://jabber.org/protocol/pubsub", new AffiliationProvider());
    pm.addExtensionProvider("options", "http://jabber.org/protocol/pubsub", new FormNodeProvider());
    // PubSub owner
    pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub#owner", new PubSubProvider());
    pm.addExtensionProvider("configure", "http://jabber.org/protocol/pubsub#owner", new FormNodeProvider());
    pm.addExtensionProvider("default", "http://jabber.org/protocol/pubsub#owner", new FormNodeProvider());
    // PubSub event
    pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", new EventProvider());
    pm.addExtensionProvider("configuration", "http://jabber.org/protocol/pubsub#event", new ConfigEventProvider());
    pm.addExtensionProvider("delete", "http://jabber.org/protocol/pubsub#event", new SimpleNodeProvider());
    pm.addExtensionProvider("options", "http://jabber.org/protocol/pubsub#event", new FormNodeProvider());
    pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new ItemsProvider());
    pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub#event", new ItemProvider());
    pm.addExtensionProvider("retract", "http://jabber.org/protocol/pubsub#event", new RetractEventProvider());
    pm.addExtensionProvider("purge", "http://jabber.org/protocol/pubsub#event", new SimpleNodeProvider());

    // Nick Exchange
    pm.addExtensionProvider("nick", "http://jabber.org/protocol/nick", new Nick.Provider());

    // Attention
    pm.addExtensionProvider("attention", "urn:xmpp:attention:0", new AttentionExtension.Provider());

    //input
    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());

}
于 2013-12-05T15:38:12.173 に答える