未在smack API中传输文件 [英] File is not being transferred in smack API

查看:122
本文介绍了未在smack API中传输文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个聊天应用程序,在其中我需要提供文件传输的支持.为此,我正在使用Smack API.但是我的文件没有被传输,我在网上搜索了File status Errorprogress 0.0
,但是它们都以相同的方式发送文件.但是我遇到了错误.
我知道关于此问题有两个问题,但没有给出适当的解决方案.

那么有人对此有想法吗?如何解决这个问题?

我尝试将 127.0.0.1 更改为 10.0.2.2 ,现在我的状态为正在协商",但经过一些尝试后,我的状态为错误". /p>

这是我的文件传输代码:

ServiceDiscoveryManager sdm = ServiceDiscoveryManager
                        .getInstanceFor(connection);
                if (sdm == null)
                    sdm = new ServiceDiscoveryManager(connection);
                sdm.addFeature("http://jabber.org/protocol/disco#info");
                sdm.addFeature("http://jabber.org/protocol/disco#item");
                sdm.addFeature("jabber:iq:privacy");
                Log.i("send file", "send file");
                FileTransferManager manager = new FileTransferManager(
                        connection);
                FileTransferNegotiator.setServiceEnabled(
                        connection, true);
                OutgoingFileTransfer transfer = manager
                        .createOutgoingFileTransfer("919974740823@127.0.0.1/Smack");
                Log.i("transfer file",
                        "outgoingfiletransfer is created");
                try {
                    OutgoingFileTransfer.setResponseTimeout(30000);
                    transfer.sendFile(
                            new File(path_file+"/"+"andr.jpeg"),
                            "Description");
                    Log.i("transfer file", "sending file");

                    Log.i("transfer file","the path is :"+path_file+"/"+"andr.jpeg");
                    while (!transfer.isDone()) {
                        try {
                            Thread.sleep(1000);
                            Log.i("transfer file",
                                    "sending file status :- "
                                            + transfer.getStatus()
                                            + " "
                                            + "progress:-"
                                            + transfer
                                                    .getProgress());
                            if (transfer.getStatus() == org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error) {
                                transfer.cancel();
                                Log.e("", "ERROR");
                                break;
                            }
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            Log.e("catch", "catch" + e);
                            e.printStackTrace();
                        }
                    }
                } catch (XMPPException e) {
                    // TODO Auto-generated catch block
                    Log.e("catch", "catch" + e);
                    e.printStackTrace();
                }
                Log.i("transfer file", "--------");
            }

任何帮助和建议将不胜感激.

谢谢

解决方案

我也遇到了同样的问题,但是添加了这一行之后

SmackConfiguration.setDefaultPacketReplyTimeout(15000);

工作正常.

I am developing a chat application in which i need to give support of file transfer. For this i am using Smack API. But my file is not being transferred and i am getting the File status Error and progress 0.0
i have googled on net but they all are used the same way to send the file. but i am getting the error.
I know there is a couple of question regarding this issue but proper solution is not given.

so is there anyone who have idea about this? How to solve this problem?

Edit:

I have try with change the 127.0.0.1 to 10.0.2.2, and now i got the status is Negotiating but after some tries i got the status Error.

Here is my code for file transfer:

ServiceDiscoveryManager sdm = ServiceDiscoveryManager
                        .getInstanceFor(connection);
                if (sdm == null)
                    sdm = new ServiceDiscoveryManager(connection);
                sdm.addFeature("http://jabber.org/protocol/disco#info");
                sdm.addFeature("http://jabber.org/protocol/disco#item");
                sdm.addFeature("jabber:iq:privacy");
                Log.i("send file", "send file");
                FileTransferManager manager = new FileTransferManager(
                        connection);
                FileTransferNegotiator.setServiceEnabled(
                        connection, true);
                OutgoingFileTransfer transfer = manager
                        .createOutgoingFileTransfer("919974740823@127.0.0.1/Smack");
                Log.i("transfer file",
                        "outgoingfiletransfer is created");
                try {
                    OutgoingFileTransfer.setResponseTimeout(30000);
                    transfer.sendFile(
                            new File(path_file+"/"+"andr.jpeg"),
                            "Description");
                    Log.i("transfer file", "sending file");

                    Log.i("transfer file","the path is :"+path_file+"/"+"andr.jpeg");
                    while (!transfer.isDone()) {
                        try {
                            Thread.sleep(1000);
                            Log.i("transfer file",
                                    "sending file status :- "
                                            + transfer.getStatus()
                                            + " "
                                            + "progress:-"
                                            + transfer
                                                    .getProgress());
                            if (transfer.getStatus() == org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error) {
                                transfer.cancel();
                                Log.e("", "ERROR");
                                break;
                            }
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            Log.e("catch", "catch" + e);
                            e.printStackTrace();
                        }
                    }
                } catch (XMPPException e) {
                    // TODO Auto-generated catch block
                    Log.e("catch", "catch" + e);
                    e.printStackTrace();
                }
                Log.i("transfer file", "--------");
            }

Any help and suggestion will be appreciated.

Thanks

解决方案

I have also having same issue but after adding this line

SmackConfiguration.setDefaultPacketReplyTimeout(15000);

Its working fine.

这篇关于未在smack API中传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆