powered by Jive Software

File transfer using Smack 4.2.3 gives service-unavailable error

I’m developing XMPP client using smack 4.2.3. Using ejabberd as an XMPP server on linux platform.
Using following code to send file:

public static void sendFile(String path, String description){
String sFqdn = currentUser.getFqdn();
if(sFqdn.equals(null)) return;
String node = XmppStringUtils.parseLocalpart(sFqdn);
String domain = XmppStringUtils.parseDomain(sFqdn);
String resource = XmppStringUtils.parseResource(sFqdn);

    try {
        EntityFullJid fqdn = entityFullFrom(node, domain, resource);
        OutgoingFileTransfer transfer = FileTransferManager.getInstanceFor(connection).createOutgoingFileTransfer(fqdn);
        transfer.sendFile(new File(path), description);
    } catch (SmackException e) {
    } catch (XmppStringprepException e) {


and to receive:

if(fileTransferManager == null){
fileTransferManager = FileTransferManager.getInstanceFor(connection);
fileTransferManager.addFileTransferListener(new FileTransferListener() {
public void fileTransferRequest(final FileTransferRequest request) {
// Accept it

            IncomingFileTransfer transfer = request.accept();
            try {
                transfer.recieveFile(new File(dir_path+request.getFileName()));
            } catch (SmackException e) {
            } catch (IOException e) {

sometimes it successfully sends a file between users, but most of the time i get this XMPP error:

D/SMACK: RECV (1): <iq xml:lang=‘en’ to=‘bob@domain/122573506394002920791746’ from=‘tom@domain/126676407739368221821682’ type=‘set’ id=‘VdzEA-77’><si xmlns=‘http: //jabber .org/protocol/si’ id=‘jsi_8874207690796615693’ mime-type=‘image/png’ profile=‘http ://jabber .org/protocol/si/profile/file-transfer’><file xmlns=‘http ://jabber .org/protocol/si/profile/file-transfer’ name=‘Screenshot.png’ size=‘250351’><desc>test file</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><r xmlns=‘urn:xmpp:sm:3’/>
D/SMACK: SENT (1): <iq to=‘tom@domain/126676407739368221821682’ id=‘VdzEA-77’ type=‘error’><error type=‘cancel’><service-unavailable xmlns=‘urn:ietf:params:xml:ns:xmpp-stanzas’/></error></iq>

In ejabberd config file I’ve successfully enabled the module “mod_proxy65”

One reason I can think of is that it might happening due to continuous presence changed by the receiver, that changes its resource.
Although I’m keeping the track of presence in Roster’s presenceChanged() method but still no success. I’m wondering if there is any way in smack to connect to server with a static resource?

One more thing, is there any example for HTTP_FILE_UPLOAD (XEP-0363), I can’t find any in smacks official documentation.

you are likely hitting this bug. https://issues.igniterealtime.org/browse/SMACK-561

a work around might be to force ibb.

thanks for the response, would you mind showing how can I force in-band bytestream by a small example??

Take a look at the FileTransferNegotiator. According to line 76, you just have to set FileTransferNegotiator.IBB_ONLY to true to force IBB as transport method.

Edit: By the way it is discouraged to use Stream Initiation to send files. Better take a look at either Jingle File Transfer or HTTP Upload. The HttpFileUploadManager should be pretty straight forward to use (take a look at the uploadFile() method.

As suggested at different platforms, I’ve already tried using HttpFileUploadManager but the issue is I can’t find org.jivesoftware.smackx.httpfileupload package in smack-extensions-4.2.3.jar
I assumed there might be no httpfileupload implementation for android yet.
Am I missing here something? Please guide me in right direction.

thanks Paul for help and suggestions. No success with forced IBB. Tried using HttpFileUploadManager but can’t find HttpFileUpload package in smackx package. Using smack v-4.2.3 please check screenshot in below comment

The HTTP File Upload code is part of the smack-experimental module.

Is it stable?
Can I use it in my client?
Are there any better alternatives?
How can I integrate experimental module in my project?

smack-experimental contains implementations of XEPs which are in experimental state (the xeps, not the imolementations).
You can include it in your client the same way you included smack-extensions.

Brother! you’ve been so helpful to me, would you mind if I ask for more help? please check my questions at Help with smack client