1

I want to implement a file transfer functionality in my chat application which I have developed in Android using SMACK and Openfire.But I got an error in sending and receiving a file.So can anybody help me to solve this problem.Thanks In advance.

Here following is a code for receiving a file.

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
        if (sdm == null)
            sdm = new ServiceDiscoveryManager(connection);
        sdm.addFeature("http://jabber.org/protocol/disco#info");
        sdm.addFeature("jabber:iq:privacy");
        XMPPConnection.DEBUG_ENABLED = true;
        // Create the file transfer manager
        final FileTransferManager managerListner = new FileTransferManager(connection);
        FileTransferNegotiator.setServiceEnabled(connection, true);
        Log.i("File transfere manager", "created");
        managerListner.addFileTransferListener(new FileTransferListener() 
        {

            @Override
            public void fileTransferRequest(FileTransferRequest request) {
                // TODO Auto-generated method stub
                Log.i("Recieve File","new file transfere request  new file transfere request   new file transfere request");
                Log.i("file request","from" + request.getRequestor());
                IncomingFileTransfer transfer = request.accept();
                Log.i("Recieve File alert dialog", "accepted");
                try {
                    transfer.recieveFile(new File("/mnt/sdcard/" + request.getFileName()));
                    while (!transfer.isDone() || (transfer.getProgress() < 1)) {

                        Thread.sleep(1000);
                        Log.i("Recieve File alert dialog", "still receiving : "+ (transfer.getProgress()) + " status "+ transfer.getStatus());
                            if (transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error)) {
                                // Log.i("Error file",
                                // transfer.getError().getMessage());
                                    Log.i("Recieve File alert dialog",
                                        "cancelling still receiving : "
                                                + (transfer.getProgress())
                                                + " status "
                                                + transfer.getStatus());
                                    transfer.cancel();
                                    break;
                            }
                    }
                }catch (XMPPException e) {
                    // TODO: handle exception
                        e.printStackTrace();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                        e.printStackTrace();
                }
            }    
        });

Here following is an error Which I have arise.

02:48:58 PM RCV  (1079277904): <iq type="error" id="6gQg0-6" to="admin-pc/cc4dd310" from="2222222222@admin-pc/Smack"><si xmlns="http://jabber.org/protocol/si" id="jsi_3030055238839806007" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="sdcard"><desc>test</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><error code="405" type="cancel"><not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
4

1 回答 1

0

该错误主要是因为您错过了添加允许共享文件的提供程序管理器的配置。请在提供程序管理器类中添加以下静态代码

// FileTransfer
pm.addIQProvider("si", "http://jabber.org/protocol/si",new StreamInitiationProvider());
pm.addIQProvider("query","http://jabber.org/protocol/bytestreams",new BytestreamsProvider());
pm.addIQProvider("open","http://jabber.org/protocol/ibb", new
         OpenIQProvider());
pm.addIQProvider("data","http://jabber.org/protocol/ibb", new
DataPacketProvider());
pm.addIQProvider("close","http://jabber.org/protocol/ibb", new
         CloseIQProvider());
pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new
         DataPacketProvider());

还将以下属性添加到您的开放式服务器以启用文件共享。

xmpp.proxy.enabled =true
xmpp.proxy.externalip =your public ip
xmpp.proxy.port  =7777

这对你有用。

于 2013-05-14T05:06:04.813 回答