无法使用任何提供的主机建立套接字

时间:2016-02-22 11:12:18

标签: android xmpp file-transfer smack

我正在使用android进行文件传输。我使用smack 4.1连接到openfire服务器。

我的问题是: 当我使用Spark to Spark文件传输时,它工作正常。但是当我将文件从 Spark传输到Android或Android到Android 时,iq收到显示错误“无法建立套接字提供主机“像这样:

<iq id="018vq-231" to="sender@domain.com/Spark 2.6.3" from="receiver@domain.com/Smack" type="error">
  <error code="-1" type="CANCEL">
    <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
    <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" xml:lang="en">Could not establish socket with any provided host</text>
  </error>
</iq>

我的接收代码是:

FileTransferManager fileTransferManager = FileTransferManager.getInstanceFor(xmppTcpConnection);

fileTransferManager .addFileTransferListener(new FileTransferListener() {
                                @Override
                                public void fileTransferRequest(final FileTransferRequest request) {

                  final IncomingFileTransfer transfer = request.accept();

                  File file = new File("Path/To/Save", transfer.getFileName());

                  transfer.recieveFile(file);

            }       
                            });

我的ProviderManager代码是:

我正在使用ServiceDiscoveryManager和ProviderManager:

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(AppConstant.xmppTcpConnection);
            sdm.addFeature("http://jabber.org/protocol/disco#info");
            sdm.addFeature("jabber:iq:privacy");
            sdm.addFeature("jabber.org/protocol/si");

ProviderManager.addIQProvider("query",
                "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());

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

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

        ProviderManager.addIQProvider("si","http://jabber.org/protocol/si",new StreamInitiationProvider());

并且,iam还将谈判者注册为:

FileTransferNegotiator fileTransferNegotiator = FileTransferNegotiator.getInstanceFor(xmppTcpConnection);

另外我在spark调试器中注意到:当spark to spark transfer时,会出现相同的消息,即无法与任何提供的主机建立套接字,但随后spark negotiate stream和file is transfer。

但是当从spark转移到android时,iq从android设备收到相同的错误并且协商是由spark启动的,但是我的文件没有收到。

任何人都可以以正确的方式指导我。

感谢。

更新

       Iq Sent : 

    <iq id="018vq-245" to="receiver@mydomain.com/Smack" from="sender@mydomain.com/Spark 2.6.3" type="set">
      <si xmlns="http://jabber.org/protocol/si" id="jsi_4357088093390871541" mime-type="image/jpeg" profile="http://jabber.org/protocol/si/profile/file-transfer">
        <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="23janNetaji.jpg" size="63856">
          <desc>Sending</desc>
        </file>
        <feature xmlns="http://jabber.org/protocol/feature-neg">
          <x xmlns="jabber:x:data" type="form">
            <field var="stream-method" type="list-single">
              <option>
                <value>http://jabber.org/protocol/bytestreams</value>
              </option>
              <option>
                <value>http://jabber.org/protocol/ibb</value>
              </option>
            </field>
          </x>
        </feature>
      </si>
    </iq>

    Received :

    <iq id="018vq-245" to="sender@mydomain.com/Spark 2.6.3" from="receiver@mydomain.com/Smack" type="result">
      <si xmlns="http://jabber.org/protocol/si">
        <feature xmlns="http://jabber.org/protocol/feature-neg">
          <x xmlns="jabber:x:data" type="submit">
            <field var="stream-method">
              <value>http://jabber.org/protocol/bytestreams</value>
              <value>http://jabber.org/protocol/ibb</value>
            </field>
          </x>
        </feature>
      </si>
    </iq>

    Sent :
    <iq id="018vq-246" to="receiver@mydomain.com/Smack" type="get">
      <query xmlns="http://jabber.org/protocol/disco#info"/>
    </iq>

    Received : 

    <iq id="018vq-246" to="sender@mydomain.com/Spark 2.6.3" from="receiver@mydomain.com/Smack" type="result">
      <query xmlns="http://jabber.org/protocol/disco#info">
        <identity category="client" name="Smack" type="pc"/>
        <feature var="http://jabber.org/protocol/commands"/>
        <feature var="http://jabber.org/protocol/xhtml-im"/>
        <feature var="jabber.org/protocol/si"/>
        <feature var="jabber:iq:privacy"/>
        <feature var="vcard-temp"/>
        <feature var="http://jabber.org/protocol/disco#items"/>
        <feature var="urn:xmpp:time"/>
        <feature var="jabber:iq:last"/>
        <feature var="jabber:x:data"/>
        <feature var="urn:xmpp:ping"/>
        <feature var="http://jabber.org/protocol/bytestreams"/>
        <feature var="http://jabber.org/protocol/ibb"/>
        <feature var="http://jabber.org/protocol/muc"/>
        <feature var="http://jabber.org/protocol/si"/>
        <feature var="http://jabber.org/protocol/xdata-validate"/>
        <feature var="jabber:iq:version"/>
        <feature var="http://jabber.org/protocol/xdata-layout"/>
        <feature var="http://jabber.org/protocol/si/profile/file-transfer"/>
        <feature var="urn:xmpp:receipts"/>
        <feature var="http://jabber.org/protocol/caps"/>
        <feature var="http://jabber.org/protocol/disco#info"/>
      </query>
    </iq>

    Sent :

    <iq id="018vq-247" to="mydomain.com" type="get">
      <query xmlns="http://jabber.org/protocol/disco#items"/>
    </iq>

    Received :

    <iq id="018vq-247" to="sender@mydomain.com/Spark 2.6.3" from="mydomain.com" type="result">
      <query xmlns="http://jabber.org/protocol/disco#items">
        <item jid="search.mydomain.com" name="User Search"/>
        <item jid="icq.mydomain.com" name="ICQ Transport"/>
        <item jid="relay.mydomain.com" name="JingleRelayNode"/>
        <item jid="facebook.mydomain.com" name="Facebook Transport"/>
        <item jid="updater.mydomain.com" name="Spark Updater"/>
        <item jid="sipark.mydomain.com" name="SIP Controller"/>
        <item jid="yahoo.mydomain.com" name="Yahoo! Transport"/>
        <item jid="rayo.mydomain.com" name="rayo"/>
        <item jid="pubsub.mydomain.com" name="Publish-Subscribe service"/>
        <item jid="manager.mydomain.com" name="Client Control Manager"/>
        <item jid="baveling.mydomain.com" name="Public Chatrooms"/>
        <item jid="msn.mydomain.com" name="MSN Transport"/>
        <item jid="conference.mydomain.com" name="Public Chatrooms"/>
        <item jid="proxy.mydomain.com" name="Socks 5 Bytestreams Proxy"/>
        <item jid="gtalk.mydomain.com" name="Google Talk Transport"/>
        <item jid="jitsi-videobridge.mydomain.com" name="JitsiVideobridge"/>
        <item jid="aim.mydomain.com" name="AIM Transport"/>
        <item jid="workgroup.mydomain.com" name="Fastpath"/>
        <item jid="xmpp.mydomain.com" name="XMPP Transport"/>
        <item jid="broadcast.mydomain.com" name="Broadcast service"/>
        <item jid="logger.mydomain.com" name="Remote Logger"/>
      </query>
    </iq>

    Sent :
    <iq id="018vq-248" to="proxy.mydomain.com" type="get">
      <query xmlns="http://jabber.org/protocol/disco#info"/>
    </iq>

    Received :

    <iq id="018vq-248" to="sender@mydomain.com/Spark 2.6.3" from="proxy.mydomain.com" type="result">
      <query xmlns="http://jabber.org/protocol/disco#info">
        <identity category="proxy" name="SOCKS5 Bytestreams Service" type="bytestreams"/>
        <feature var="http://jabber.org/protocol/bytestreams"/>
        <feature var="http://jabber.org/protocol/disco#info"/>
      </query>
    </iq>

    Sent :

    <iq id="018vq-249" to="proxy.mydomain.com" type="get">
      <query xmlns="http://jabber.org/protocol/bytestreams"/>
    </iq>

    Received :

    <iq id="018vq-249" to="sender@mydomain.com/Spark 2.6.3" from="proxy.mydomain.com" type="result">
      <query xmlns="http://jabber.org/protocol/bytestreams">
        <streamhost jid="proxy.mydomain.com" host="mydomain.com" port="7777"/>
      </query>
    </iq>

    Sent :

    <iq id="018vq-250" to="receiver@mydomain.com/Smack" type="set">
      <query xmlns="http://jabber.org/protocol/bytestreams" sid="jsi_4357088093390871541" mode="tcp">
        <streamhost jid="sender@mydomain.com/Spark 2.6.3" host="192.168.1.201" port="7777"/>
        <streamhost jid="proxy.mydomain.com" host="mydomain.com" port="7777"/>
      </query>
    </iq>

 Received :
    <iq id="018vq-250" to="sender@mydomain.com/Spark 2.6.3" from="receiver@mydomain.com/Smack" type="error">
      <error code="-1" type="CANCEL">
        <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
        <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" xml:lang="en">Could not establish socket with any provided host</text>
      </error>
    </iq>

    Sent :
    <iq id="018vq-251" to="receiver@mydomain.com/Smack" type="set">
      <open xmlns="http://jabber.org/protocol/ibb" block-size="4096" sid="jsi_4357088093390871541" stanza="iq"/>
    </iq>

在发送方收到错误IQ后,发送方再次向接收方发送IQ以进行文件传输协商流,但在此iq之后没有从接收方接收到iq。

另外,我正在使用以下smack libs:

 compile 'org.igniterealtime.smack:smack-android:4.1.1'
 compile 'org.igniterealtime.smack:smack-core:4.1.1'
 compile 'org.igniterealtime.smack:smack-tcp:4.1.1'
 compile 'org.igniterealtime.smack:smack-extensions:4.1.1'

1 个答案:

答案 0 :(得分:3)

我得到了解决方案。问题在于smack sdk。

Smack在文件传输实现中有一些错误:在我的情况下,发起者提供了字节流和ibb方法,响应者接受两种(这是错误的)方法。

(参考:@vitalyster在这里回答Getting ExecutionException on receiving file using asmack in Android

它应该只接受一个。 因此,在创建FileNegotiator时,我只提供了一个流:

FileTransferNegotiator fileTransferNegotiator = FileTransferNegotiator.getInstanceFor(xmppTcpConnection);
FileTransferNegotiator.IBB_ONLY = true; 

现在文件传输工作正常。

谢谢大家。