Android的文件传输通过XMPP和openfire的不工作文件传输、工作、Android、openfire

2023-09-05 10:55:55 作者:.蟲児飛′

问题:不能接收发送给我通过XMPP和openfire的服务器Android应用程序的文件。我可以成功,虽然发送文件。我使用的asmack罐子的 asmack-JSE-buddycloud-2010.12.11.jar 的

Problem : Can't receive a file sent to my android app via XMPP and OpenFire Server. I can successfully send a file though. The asmack jar I am using is asmack-jse-buddycloud-2010.12.11.jar

code

    connConfig = new ConnectionConfiguration("beta.myCompany.co.uk", 5222);
    connConfig.setSASLAuthenticationEnabled(true);
    try {
        connect("username", "password");
    } catch (Exception e) {
        e.printStackTrace();
    }

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    if(sdm == null)
        sdm = new ServiceDiscoveryManager(connection);

    fileTransferManager = new FileTransferManager(connection);
    FileTransferNegotiator.setServiceEnabled(connection, true);

fileTransferManager.addFileTransferListener(new FileTransferListener() {
    @Override
    public void fileTransferRequest(FileTransferRequest request) {
        IncomingFileTransfer transfer = request.accept();
        try {
            FileOutputStream fos = openFileOutput(request.getFileName(), Context.MODE_PRIVATE);
            InputStream stream = transfer.recieveFile();//THIS FAILS!
            fos.write(IOUtils.toByteArray(stream));
            fos.close();    
        } catch (Exception e) {
            e.printStackTrace();
        }
}

错误(如果文件通过星火发送的)

Error (If file is sent via Spark) :

在执行错误: - 所造成的:   java.util.concurrent.ExecutionException:从文件中没有响应   传递启动:

Error in execution: -- caused by: java.util.concurrent.ExecutionException: No response from file transfer initiator:

错误(如果文件通过Adium的的发送)

Error (If file is sent via Adium) :

java.util.concurrent.ExecutionException:无法建立套接字   任何提供的主机:项目未找到(404)无法建立套接字   任何提供的主机

java.util.concurrent.ExecutionException: Could not establish socket with any provided host: item-not-found(404) Could not establish socket with any provided host

错误(如果文件是通过我的应用程序的另一个实例发送的)

Error (If file is sent via another instance of my app) :

在执行错误: - 所造成的:   java.util.concurrent.ExecutionException: - 所造成的:无回应   从远程客户端:

嵌入式技术技术文库 嵌入式技术电子技术方案

Error in execution: -- caused by: java.util.concurrent.ExecutionException: -- caused by: No response from remote client:

我的日志:(当试图接收来自星火文件)

看来,我送这个错误! (不接受的话)。为什么会这样?

It appears that I am SENDING this error! (Not receiving it). Why would this be?

> 05-01 12:49:36.013: I/System.out(1000): 12:49:35 PM SENT (1093411736):
> <iq id="791-6222" to="beta.myCompany.co.uk"
> from="theUsername@beta.myCompany.co.uk/BAM-1918973529" type="error"><error
> code="501" type="CANCEL"><feature-not-implemented
> xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

附加日志

05-01 14:46:06.133: I/System.out(1370): 02:46:06 PM RCV  (1093401112): <iq id="eRi5A-72" to="myUsername@beta.myCompany.co.uk/BAM-1755858011" from="friendsUsername@beta.myCompany.co.uk/Spark 2.6.3" type="set"><si xmlns="http://jabber.org/protocol/si" id="jsi_5991130279184702850" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="Test.rtf" size="318"><desc>Sending 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>
05-01 14:46:08.283: I/System.out(1370): 02:46:08 PM SENT (1093401112): <iq id="eRi5A-72" to="friendsUsername@beta.myCompany.co.uk/Spark 2.6.3" from="myUsername@beta.myCompany.co.uk/BAM-1755858011" 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></field></x></feature></si></iq>
05-01 14:46:08.312: I/System.out(1370): 02:46:08 PM RCV  (1093401112): <iq id="eRi5A-73" to="myUsername@beta.myCompany.co.uk/BAM-1755858011" type="get" from="friendsUsername@beta.myCompany.co.uk/Spark 2.6.3"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
05-01 14:46:14.352: W/System.err(1370): Error in execution: 
05-01 14:46:14.352: W/System.err(1370):   -- caused by: java.util.concurrent.ExecutionException: No response from file transfer initiator:[
[ERROR LOG IS HERE]
05-01 14:46:14.732: I/System.out(1370): 02:46:14 PM SENT (1093401112): <iq id="eRi5A-73" to="friendsUsername@beta.myCompany.co.uk/Spark 2.6.3" type="result"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="client" name="Smack" type="pc"/><feature var="http://jabber.org/protocol/caps"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/si/profile/file-transfer"/><feature var="http://jabber.org/protocol/si"/><feature var="http://jabber.org/protocol/ibb"/></query></iq>
05-01 14:46:14.773: I/System.out(1370): 02:46:14 PM RCV  (1093401112): <iq id="eRi5A-77" to="myUsername@beta.myCompany.co.uk/BAM-1755858011" type="set" from="friendsUsername@beta.myCompany.co.uk/Spark 2.6.3"><query xmlns="http://jabber.org/protocol/bytestreams" sid="jsi_5991130279184702850" mode="tcp"><streamhost jid="friendsUsername@beta.myCompany.co.uk/Spark 2.6.3" host="10.95.104.25" port="7777"/><streamhost jid="proxy.beta.myCompany.co.uk" host="127.0.1.1" port="7777"/></query></iq>
05-01 14:46:29.783: I/System.out(1370): 02:46:29 PM RCV  (1093401112): <iq type="get" id="537-7113" from="beta.myCompany.co.uk" to="myUsername@beta.myCompany.co.uk/BAM-1755858011"><ping xmlns="urn:xmpp:ping"/></iq>
05-01 14:46:29.843: I/System.out(1370): 02:46:29 PM SENT (1093401112): <iq id="537-7113" to="beta.myCompany.co.uk" from="myUsername@beta.myCompany.co.uk/BAM-1755858011" type="error"><error code="501" type="CANCEL"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

推荐答案

使用

Use 

而不是

InputStream stream = transfer.receive();

您卡住PacketReader线程。第一种方法将产生它自己的线程来读取特定的数据包被传输构成该文件的部分。如果使用第二种方法,你必须酿出自己的线程来完成实际的文件读写。

You are blocking the PacketReader thread. The first method will spawn it's own thread to read the specific packets that make up the parts of the file being transferred. If you use the second method you have to spawn a thread of your own to do the actual file reading and writing.