I am struggling with file transfer in android.I am using smack 4.1 to connect to openfire server.
My problem is: When i am using Spark to Spark file transfer, it works fine.But when i transfer file from Spark to Android or Android to Android, The iq received showing error "Could not establish socket with any provided host" like this:
<iq id="018vq-231" to="[email protected]/Spark 2.6.3" from="[email protected]/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>
My code for receiving is:
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);
}
});
My ProviderManager code is:
I am using ServiceDiscoveryManager and ProviderManager as:
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());
and , iam also registering a Negotiator as:
FileTransferNegotiator fileTransferNegotiator = FileTransferNegotiator.getInstanceFor(xmppTcpConnection);
Also i noted in spark debugger that: When spark to spark transfer, the same message occurs i.e. Could not establish socket with any provided host but then spark negotiate stream and file is transfered.
But while transfering from spark to android,The iq with same error received from android device and the negotiation is initiated by spark but file is not received at my end.
Can anyone please guide me the right way.
Thanks.
Update:
Iq Sent :
<iq id="018vq-245" to="[email protected]/Smack" from="[email protected]/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="[email protected]/Spark 2.6.3" from="[email protected]/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="[email protected]/Smack" type="get">
<query xmlns="http://jabber.org/protocol/disco#info"/>
</iq>
Received :
<iq id="018vq-246" to="[email protected]/Spark 2.6.3" from="[email protected]/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="[email protected]/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="[email protected]/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="[email protected]/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="[email protected]/Smack" type="set">
<query xmlns="http://jabber.org/protocol/bytestreams" sid="jsi_4357088093390871541" mode="tcp">
<streamhost jid="[email protected]/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="[email protected]/Spark 2.6.3" from="[email protected]/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="[email protected]/Smack" type="set">
<open xmlns="http://jabber.org/protocol/ibb" block-size="4096" sid="jsi_4357088093390871541" stanza="iq"/>
</iq>
After error IQ received on sender side,sender again sent IQ to receiver for file transfer negotiatiating stream,but no iq received from receiver side after this iq.
Also, i am using following 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'
I got the solution.The problem is with smack sdk.
Smack have some bugs in file transfer implementation: in my case initiator offered bytestreams and ibb methods, responder accept both (which is wrong) methods.
(Reference: answer by @vitalyster here Getting ExecutionException on receiving file using asmack in Android )
It should accept only one. So while creating FileNegotiator, i offered only one stream as:
FileTransferNegotiator fileTransferNegotiator = FileTransferNegotiator.getInstanceFor(xmppTcpConnection);
FileTransferNegotiator.IBB_ONLY = true;
Now files transfer is working fine.
Thanks everyone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With