2012-05-01 32 views
8

Sự cố: Không thể nhận tệp được gửi tới ứng dụng Android của tôi qua XMPP và OpenFire Server. Tôi có thể gửi một tập tin thành công. Jar asmack Tôi đang sử dụng là asmack-JSE-Buddycloud-2010.12.11.jarTruyền tệp của Android không hoạt động qua XMPP và OpenFire

:

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

Lỗi (Nếu tập tin được gửi qua Spark):

Lỗi khi thực hiện: - do: java.util.concurrent.ExecutionException: Không có phản hồi từ tệp chuyển khởi xướng:

Lỗi (Nếu tập tin được gửi qua Adium):

java.util.concurrent.ExecutionException: Không thể thiết lập ổ cắm với bất kỳ máy chủ cung cấp: item- không tìm thấy (404) Không thể thiết lập ổ cắm với bất kỳ máy chủ nào được cung cấp

Lỗi (Nếu tập tin được gửi qua một thể hiện của ứng dụng của tôi):

Lỗi trong thực hiện: - gây ra bởi: java.util.concurrent.ExecutionException: - do: Không có phản ứng từ khách hàng từ xa:

bản ghi của tôi: (Khi cố gắng để nhận tập tin từ Spark)

dường như tôi đang GỬI lỗi này! (Không nhận được nó). Tại sao điều này lại là?

> 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="[email protected]/BAM-1918973529" type="error"><error 
> code="501" type="CANCEL"><feature-not-implemented 
> xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq> 

Logs tắm:

05-01 14:46:06.133: I/System.out(1370): 02:46:06 PM RCV (1093401112): <iq id="eRi5A-72" to="[email protected]/BAM-1755858011" from="[email protected]/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="[email protected]/Spark 2.6.3" from="[email protected]/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="[email protected]/BAM-1755858011" type="get" from="[email protected]/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="[email protected]/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="[email protected]/BAM-1755858011" type="set" from="[email protected]/Spark 2.6.3"><query xmlns="http://jabber.org/protocol/bytestreams" sid="jsi_5991130279184702850" mode="tcp"><streamhost jid="[email protected]/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="[email protected]/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="[email protected]/BAM-1755858011" type="error"><error code="501" type="CANCEL"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq> 
+0

Các thông báo XMPP trước khi lỗi 501 từ cả hai phía sẽ là thú vị. – Flow

+0

Cảm ơn luồng phản hồi của bạn. Tôi đã thêm nhiều nhật ký từ ứng dụng của mình từ trước 501. –

+0

hi @AndyA bạn có thể giúp tôi trong http://stackoverflow.com/questions/11666963/file-is-not-being-transferred-in-smack- này không api – juned

Trả lời

3

Sử dụng

transfer.receiveFile(myLocalFile); 

thay vì

InputStream stream = transfer.receive(); 

Bạn đang chặn thread PacketReader. Phương thức đầu tiên sẽ sinh ra luồng riêng của nó để đọc các gói tin cụ thể tạo nên các phần của tập tin đang được chuyển. Nếu bạn sử dụng phương pháp thứ hai, bạn phải sinh ra một chuỗi của riêng bạn để thực hiện đọc và ghi tệp thực tế.

+0

Tác phẩm này. Các mã sau đây có thể được sử dụng để đọc các tập tin. IncomingFileTransfer transfer = request.accept(); transfer.recieveFile (tệp mới (getExternalFilesDir (null), transfer.getFileName())); Chuỗi ký tự; BufferedReader br = new BufferedReader (tệp FileReader mới (tệp mới (getExternalFilesDir (null), transfer.getFileName()))); while ((line = br.readLine())! = null) System.out.println (dòng); –

+1

Và bạn cũng cần sự cho phép sau trong tệp kê khai của mình ... \t

+0

Tôi đang gặp phải vấn đề tương tự, bạn có thể xem qua [link] này (http://stackoverflow.com/q/28271210/4358880) và giúp đỡ trong việc giải quyết vấn đề –

0

tôi đã tạo ra một chương trình đơn giản của Java, với một số copy_paste mã người dùng khác, nhưng điểm + là nó đang làm việc, tôi đã cố gắng b này/w LocalHost - SPark client - javaProgram

bạn có thể gửi txt.tệp cho người dùng khác, được tạo trong phần Người dùng openFile.

Lưu ý: vui lòng thay đổi bất kỳ điều gì nếu bạn muốn bất kỳ chi tiết nào trong lớp Xmpp.test .

Download Xmpp File Transfer "Java Code" From Here

+0

Tôi đã thử điều này nhưng dòng này luôn luôn excutes: 'if (transfer.getStatus(). bằng (Status.refused) \t \t \t \t || transfer.getStatus(). equals (Status.error) \t \t \t \t || transfer.getStatus(). equals (Status.cancelled)) { \t \t \t System.out \t \t \t \t \t .println ("lỗi bị từ chối bị hủy" + transfer.getError()); ', có nghĩa là ngay cả khi nó được thực hiện, việc gửi tệp không thành công. Tôi không hiểu tại sao tôi lại gặp lỗi này. –

Các vấn đề liên quan