3

我正在开发一个聊天应用程序,我需要在其中在点对点聊天用户之间发送图像。现在我能够发送图像并且我的文件接收器也接受请求并开始接收文件。

但打印状态始终保持打印: LOG: Progress:0.0 & Status:In Progress

并在完成线程后 - LOG ###Filetransfer 未完成。状态:进行中

如果我让这个线程运行删除计数,它会继续打印 - 进度:0.0 & 状态:进行中

有时会稍后收到完整的图像..这需要很长时间,而且要花很多时间一半或大小为 0。

private ServiceDiscoveryManager sdm;    
 if (sdm == null)
                    sdm = new ServiceDiscoveryManager(connection);
                Log.v("---fileReceive----","after discover connectin.....");
                sdm.addFeature("http://jabber.org/protocol/disco#info");
                sdm.addFeature("jabber:iq:privacy");

                ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
                ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
                ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
                ProviderManager.getInstance().addIQProvider("si", "http://jabber.org/protocol/si", new StreamInitiationProvider());
                ProviderManager.getInstance().addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());                    
                ProviderManager.getInstance().addIQProvider("open", "http://jabber.org/protocol/ibb", new OpenIQProvider());
                ProviderManager.getInstance().addIQProvider("data", "http://jabber.org/protocol/ibb", new DataPacketProvider());
                ProviderManager.getInstance().addIQProvider("close", "http://jabber.org/protocol/ibb", new CloseIQProvider());
                ProviderManager.getInstance().addExtensionProvider("data", "http://jabber.org/protocol/ibb", new DataPacketProvider());

                sdm = ServiceDiscoveryManager.getInstanceFor(connection);


                FileTransferNegotiator.setServiceEnabled(connection, true);
                FileTransferNegotiator.IBB_ONLY = true; 
                manager = new FileTransferManager(connection);
                // Create the listener
                //  fListner=new FileTransferListener() {
                manager.addFileTransferListener(new FileTransferListener() {
                    @Override
                    public void fileTransferRequest(FileTransferRequest request) {
                        // TODO Auto-generated method stub
                        Log.v("----Recieve File",
                                "new file transfere requesttttt------------");

                        Log.v("-----file request","from" + request.getRequestor());

                        // Accept it

                        try {
                            IncomingFileTransfer transfer = request.accept();
                            Log.v("----transfer--","accepted");

                            double percents = 0.0;
                            int currentCycle = 0;
                            transfer.recieveFile(new File( Environment.getExternalStorageDirectory().getPath()+"/"+transfer.getFileName()));


                              while(!transfer.isDone() && currentCycle < 100) {
                                    if(transfer.getStatus().equals(Status.in_progress)) {
                                        percents = ((int) (transfer.getProgress()*10000)) / 100.0;
                                                  //percents is 100.0 after 1 cycle
                                        Log.i(LOG, "Filetransfer Progress: "+percents + " Status: "+transfer.getStatus().toString());
                                    } else if (transfer.getStatus().equals(Status.error)) {
                                        Log.e(LOG, "FileTransfer ERROR"+transfer.getError().getMessage());
                                        break;
                                    } 
                                    currentCycle ++;
                                    try {
                                        Thread.sleep(1000);
                                    } catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }
                                }

                                if(transfer.getStatus().equals(Status.complete)) {
                                    if (onFileReceivedListener != null) {
                                       onFileReceivedListener.onFileReceived(transfer);
                                    }
                                }else{
                                    Log.e(LOG, "###Filetransfer not complete. Status:" + transfer.getStatus().toString());
                                                        //FILE IS HERE  
                                }
                        } catch (XMPPException e) {
                            e.printStackTrace();
                        }
                    }
                }); `

任何提示或帮助表示赞赏。

4

1 回答 1

0

我最近确实对 asmack 和 smackx 有一点经验,对它们不能太乐观。

我不知道你的问题究竟来自哪里,但我可以告诉你这是正常的。在任何进度实际开始之前,您首先会得到一个 progress = 0 的负载。如果您发送的是一个小文件,那么它发送的速度很快,以至于没有任何实际进展。

但是,如果您成功发送了一个更大的文件,此功能确实可以很好地工作,并且会给您大致的进度。

最后我们得出的结论是,这个功能只是有缺陷和限制,并实现了我们自己的文件传输 xmpp 消息并处理通过我们自己的服务器发送它。像这样,您还可以分组(MUC)将文件发送给离线的人,并在双方(发送和接收)方面都取得了不错的进展。

于 2013-03-14T10:37:11.627 回答