8

问题:无法接收通过 XMPP 和 OpenFire 服务器发送到我的 android 应用程序的文件。我可以成功发送文件。我使用的 asmack jar 是asmack-jse-buddycloud-2010.12.11.jar

代码

    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();
        }
}

错误(如果文件是通过 Spark 发送的

执行错误:- 由:java.util.concurrent.ExecutionException:文件传输发起者无响应:

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

java.util.concurrent.ExecutionException:无法与任何提供的主机建立套接字:item-not-found(404) 无法与任何提供的主机建立套接字

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

执行错误:- 由:java.util.concurrent.ExecutionException 引起:- 由:远程客户端无响应:

我的日志:(尝试从 Spark 接收文件时)

看来我正在发送此错误!(没有收到)。为什么会这样?

> 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>
4

2 回答 2

3

利用

transfer.receiveFile(myLocalFile);

代替

InputStream stream = transfer.receive();

您正在阻塞 PacketReader 线程。第一种方法将产生它自己的线程来读取构成正在传输的文件部分的特定数据包。如果您使用第二种方法,则必须生成自己的线程来执行实际的文件读取和写入。

于 2012-05-01T13:47:50.353 回答
0

我创建了一个简单的 Java 程序,其中包含一些其他用户代码的复制粘贴,但关键是它正在工作,我已经尝试过这个 b/wLocalHost - SPark client - javaProgram

您可以将 txt.file 发送给在 openFile 用户部分创建的其他用户。

注意:如果您想要 Xmpp.test 类中的任何详细信息,请更改任何内容。

从这里下载 Xmpp 文件传输“Java 代码”

于 2014-08-07T07:35:00.300 回答