我长期以来一直在解决以下问题,但根本无法解决。我尝试使用smack for Android通过xmpp进行文件传输,代码如下:
fTManager = FileTransferManager.getInstanceFor(connection);
fTManager.addFileTransferListener(new FileTransferListener() {
@Override
public void fileTransferRequest(FileTransferRequest fileTransferRequest) {
String requerstor = fileTransferRequest.getRequestor();
try {
IncomingFileTransfer transfer = fileTransferRequest.accept();
transfer.recieveFile(new File(getExternalFilesDir(null), transfer.getFileName()));
bufferedReader = new BufferedReader(new FileReader(new File(getExternalFilesDir(null), transfer.getFileName())));
String line;
while ((line = bufferedReader.readLine()) != null)
Log.i("Line", "LINE " + line);
while (!transfer.isDone()) {
Thread newThread = new Thread();
Log.i("FileTransferManager", "File transfer is " + String.format("%1$,.2f", transfer.getProgress() * 100) + "% complete.");
try {
newThread.sleep(1000);
} catch (InterruptedException e) {e.printStackTrace();}
}
if (transfer.isDone())
Log.i("FileTransferManager", "Transfer status is:" + transfer.getStatus());
if (transfer.getError() != null)
Log.i("FileTransferManager", "Transfer error occurred:" + transfer.getError().getMessage());
if(transfer.getException() != null)
transfer.getException().printStackTrace();
}
catch (SmackException e) {e.printStackTrace();}
catch (IOException e) { e.printStackTrace();}
如果我收到文件传输请求,则可以显示请求者和文件名。但是如果transfer.recieveFile(new File(getExternalFilesDir(null), transfer.getFileName()));
发生以下错误:
03-23 12:47:37.890 888-916/? W/System.err﹕ org.jivesoftware.smack.SmackException: Error in execution
03-23 12:47:37.890 888-916/? W/System.err﹕ at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.negotiateStream(IncomingFileTransfer.java:199)
03-23 12:47:37.900 888-916/? W/System.err﹕ at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.access$100(IncomingFileTransfer.java:57)
03-23 12:47:37.900 888-916/? W/System.err﹕ at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$1.run(IncomingFileTransfer.java:129)
03-23 12:47:37.900 888-916/? W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
03-23 12:47:37.900 888-916/? W/System.err﹕ Caused by: java.util.concurrent.ExecutionException: org.jivesoftware.smack.SmackException: SOCKS5 negotiation failed
03-23 12:47:37.920 888-916/? W/System.err﹕ at java.util.concurrent.FutureTask.report(FutureTask.java:93)
03-23 12:47:37.920 888-916/? W/System.err﹕ at java.util.concurrent.FutureTask.get(FutureTask.java:177)
03-23 12:47:37.920 888-916/? W/System.err﹕ at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.negotiateStream(IncomingFileTransfer.java:193)
03-23 12:47:37.930 888-916/? W/System.err﹕ ... 3 more
03-23 12:47:37.930 888-916/? W/System.err﹕ Caused by: org.jivesoftware.smack.SmackException: SOCKS5 negotiation failed
03-23 12:47:37.930 888-916/? W/System.err﹕ at org.jivesoftware.smackx.bytestreams.socks5.Socks5Client$1.call(Socks5Client.java:105)
03-23 12:47:37.930 888-916/? W/System.err﹕ at org.jivesoftware.smackx.bytestreams.socks5.Socks5Client$1.call(Socks5Client.java:80)
03-23 12:47:37.940 888-916/? W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-23 12:47:37.940 888-916/? W/System.err﹕ ... 1 more
我正在使用smack-4.1.0-rc4。有人知道我的线索吗?我很感激一些建议。