使用smack 4.2.4发送文件

时间:2018-05-22 10:18:58

标签: java android xmpp smack instant-messaging

我正在尝试使用smack 4.2.4发送图像和文件,而我的服务器是jabb3r.org但是没有任何进程,它会向我发送此错误:

  
    

从fattaneh123@jabb3r.org/Xabber_egtxJrjU收到的XMPP错误回复:XMPPError:service-unavailable - wait

  

我测试了xabber中的文件发送功能并且安全聊天,它们与jabb3r一起正常工作,但是他们在proxy.hot-chilli.net:5281/upload上传文件 我怎么能访问这个网址并发送我的文件

public void send(String id, String path) throws XmppStringprepException{
        ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
        if (sdm == null) {
            sdm = ServiceDiscoveryManager.getInstanceFor(connection);
            sdm.addFeature("http://jabber.org/protocol/disco#info");
            sdm.addFeature("jabber:iq:privacy");
        }
        FileTransferManager manager = FileTransferManager.getInstanceFor(connection);
        final OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(JidCreate.entityFullFrom("fattaneh123@jabb3r.org/Xabber_egtxJrjU"));


        FileTransferNegotiator.IBB_ONLY = true;

        final File file = new File(path);
        try {
            FileTransferNegotiator.getInstanceFor(connection).negotiateOutgoingTransfer(JidCreate.entityFullFrom("fattaneh123@jabb3r.org/Xabber_egtxJrjU"), transfer.getStreamID(), file.getName(), file.length(), "ali", 10000);
        } catch (XMPPException.XMPPErrorException e) {
            e.printStackTrace();
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
        } catch (SmackException.NoResponseException e) {
            e.printStackTrace();
        } catch (FileTransferException.NoAcceptableTransferMechanisms noAcceptableTransferMechanisms) {
            noAcceptableTransferMechanisms.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        new AsyncTask<Void, Void, Void>() {


            protected void onPreExecute() {

            }

            @Override
            protected Void doInBackground(Void... params) {
                try {
                    transfer.sendFile(file,file.getName());
                } catch (SmackException e) {
                    e.printStackTrace();
                }
                while (!transfer.isDone()) {
                    if (transfer.getStatus().equals("Error")) {
                        Log.d("file transfer",
                                "ERROR!!! " + transfer.getError());

                    } else if (transfer.getStatus().equals("Cancelled")
                            || transfer.getStatus().equals("Refused")) {
                        Log.d("file transfer",
                                "Cancelled!!! " + transfer.getError());
                    }
                    try {
                        Thread.sleep(1000L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                return null;
            }

            protected void onPostExecute(Void result) {

                if (transfer.getStatus().equals("Refused")
                        || transfer.getStatus().equals("Error")
                        || transfer.getStatus().equals("Cancelled")) {
                    Log.i("file transfer", "refused cancelled error "
                            + transfer.getError());

                } else {

                    Log.i("file transfer", "Success: " + transfer.getException().getMessage());
                }
            }

            ;
        }.execute();

    }

0 个答案:

没有答案