Skip to content Skip to sidebar Skip to footer

Failed To Transfer File Using Smack 'xmpperror: Service-unavailable - Cancel'

I'm trying to transfer file using smack extension library 4.2.0 but couldn't able to successfully transfer file. When i try to transfer file this is the error I'm getting org.jive

Solution 1:

I had same problem, I investigated the stanza and solved it this way.

Many people use "/Smack" or "/Resource" as resource part in jid, but that can be done another way.

Resource path is changing with every presence changed of user. Lets say we want to send image to this user: "user1@mydomain"

You must add "/Resource" or "/Smack" part to this jid and it become this: user1@mydomain/Resource

user1@mydomain/Smack

But resource path is changing with presence so you must follow every presence change to update resource path. Best way is to get user presence is in roster listener and in presencheChanged() method you get last user resource part like this:

Roster roster=getRoster();
roster.addRosterListener(newRosterListener() {
                @OverridepublicvoidentriesAdded(Collection<Jid> addresses) {
                    Log.d("entriesAdded", "ug");
                    context.sendBroadcast(newIntent("ENTRIES_ADDED"));
                }

                @OverridepublicvoidentriesUpdated(Collection<Jid> addresses) {
                    Log.d("entriesUpdated", "ug");
                }

                @OverridepublicvoidentriesDeleted(Collection<Jid> addresses) {
                    Log.d("entriesDeleted", "ug");
                }

                @OverridepublicvoidpresenceChanged(Presence presence) {
                    Log.d("presenceChanged", "ug");
                    //Resource from presenceString resource = presence.getFrom().getResourceOrEmpty().toString();
                    //Update resource part for user in DB or preferences//...
                }
            });
}

Resource string will be some generated string like "6u1613j3kv" and jid will become: user1@mydomain/6u1613j3kv

That means that you must create your outgoing transfer like this:

EntityFullJidjid= JidCreate.entityFullFrom("user1@mydomain/6u1613j3kv"); 
OutgoingFileTransfertransfer= manager.createOutgoingFileTransfer(jid)

In your case like this:

EntityBareJidjid= JidCreate.entityBareFrom(sendTo);
EntityFullJidentityFullJid= JidCreate.entityFullFrom(jid + resource);

Where resource is resourcepart from Presence in listener.

And that is how i have solved my problem with file transfer on smack and Openfire.

Also to mention you must add following properties in your Openfire server:

xmpp.proxy.enabled - true
xmpp.proxy.externalip - MY_IP_ADDRESS
xmpp.proxy.port -7777

Just to mention, I am using Openfire 4.0.2 and Smack 4.2.2.

Also this can be configured the easy way, just set the resource on

XMPPTCPConnectionConfiguration.Builder .

like

XMPPTCPConnectionConfiguration.BuilderconfigurationBuilder= 
XMPPTCPConnectionConfiguration.builder(); 

configurationBuilder.setResource("yourResourceName");

Post a Comment for "Failed To Transfer File Using Smack 'xmpperror: Service-unavailable - Cancel'"