1
votes

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) {
        e.printStackTrace();
    } catch (XmppStringprepException e) {
        e.printStackTrace();
    }

}

and to receive:

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

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

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’><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></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.

1

1 Answers

0
votes

After discussion at ignite realtime's forum, I found out that I was hitting a bug.

A work around to this bug is forced in-band byte stream.

Setting FileTransferNegotiator.IBB_ONLY to true did the trick for me.

Please take a look at line 76 in FileTransferNegotiator class as well.