Smack 4.1 回复超时内无响应 [英] Smack 4.1 No Response within reply timeout

查看:32
本文介绍了Smack 4.1 回复超时内无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的安卓应用中使用以下代码:

I am using the following code in my android app:

Thread d = new Thread(new Runnable() {

    @Override
    public void run() {
        SmackConfiguration.setDefaultPacketReplyTimeout(10000);
        XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                  .setUsernameAndPassword("admin", "password")
                  .setServiceName("192.168.0.200")
                  .setHost("192.168.0.200")
                  .setPort(5223).setSecurityMode(SecurityMode.ifpossible)
                  .build();

        AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
        try {
            conn2.connect();
            conn2.login();

            Presence presence = new Presence(Presence.Type.unavailable);
            presence.setStatus("Gone fishing");
            // Send the packet (assume we have an XMPPConnection instance called "con").
            conn2.sendStanza(presence);

        } catch (SmackException | IOException | XMPPException e) {
            e.printStackTrace();
            Log.d("TAG", e.toString());
        }

        ChatManager chatmanager = ChatManager.getInstanceFor(conn2);
        Chat newChat = chatmanager.createChat("harsh@192.168.0.200");

        try {
            newChat.sendMessage("Howdy!");
        }
        catch (NotConnectedException e) {
            e.printStackTrace();
        }
    }
});

d.start();

这是返回此错误:

05-14 18:07:48.030:D/TAG(19470):org.jivesoftware.smack.SmackException$NoResponseException: 无响应在回复超时内收到.超时为 10000 毫秒(~10 秒).用过的过滤器:未使用过滤器或过滤器为空".

05-14 18:07:48.030: D/TAG(19470): org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 10000ms (~10s). Used filter: No filter used or filter was 'null'.

我在 192.168.0.200 设置了一个本地服务器.有人能告诉我是什么问题吗?

I have set up a local server at 192.168.0.200. Could anybody tell me what the problem is?

我正在使用这些库:

推荐答案

我已成功连接到本地 openfire 服务器并在没有 SSL 的情况下登录.这是我的代码

I have successfully connected to local openfire server and logged in without SSL. Here is my code

public class NewClientActivity extends Activity {
    EditText etUsername, etPassword;
    Button bSubmit;
    AbstractXMPPConnection mConnection;
    ConnectionListener connectionListener = new ConnectionListener() {
        @Override
        public void connected(XMPPConnection xmppConnection) {
            Log.d("xmpp", "connected");
            try {
                SASLAuthentication.registerSASLMechanism(new SASLMechanism() {
                    @Override
                    protected void authenticateInternal(CallbackHandler callbackHandler) throws SmackException {

                    }

                    @Override
                    protected byte[] getAuthenticationText() throws SmackException {
                        byte[] authcid = toBytes('\u0000' + this.authenticationId);
                        byte[] passw = toBytes('\u0000' + this.password);
                        return ByteUtils.concact(authcid, passw);
                    }

                    @Override
                    public String getName() {
                        return "PLAIN";
                    }

                    @Override
                    public int getPriority() {
                        return 410;
                    }

                    @Override
                    public void checkIfSuccessfulOrThrow() throws SmackException {

                    }

                    @Override
                    protected SASLMechanism newInstance() {
                        return this;
                    }
                });
                mConnection.login();
            } catch (XMPPException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(NewClientActivity.this, "Incorrect username or password", Toast.LENGTH_LONG).show();
                    }
                });
                e.printStackTrace();
            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void authenticated(XMPPConnection xmppConnection, boolean b) {
            Log.d("xmpp", "authenticated");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(NewClientActivity.this,"Logged in successfully...",Toast.LENGTH_LONG ).show();
                }
            });
        }

        @Override
        public void connectionClosed() {
            Log.d("xmpp", "connection closed");
        }

        @Override
        public void connectionClosedOnError(Exception e) {
            Log.d("xmpp", "cononection closed on error");
        }

        @Override
        public void reconnectionSuccessful() {
            Log.d("xmpp", "reconnection successful");
        }

        @Override
        public void reconnectingIn(int i) {
            Log.d("xmpp", "reconnecting in " + i);
        }

        @Override
        public void reconnectionFailed(Exception e) {
            Log.d("xmpp", "reconnection failed");
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_client);
        findViews();
    }

    private void findViews() {
        etUsername = (EditText) findViewById(R.id.etUsername);
        etPassword = (EditText) findViewById(R.id.etPassword);
        bSubmit = (Button) findViewById(R.id.bSubmit);
        bSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String[] params = new String[]{etUsername.getText().toString(), etPassword.getText().toString()};
                new Connect().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
            }
        });
    }

    class Connect extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {

            XMPPTCPConnectionConfiguration config = null;
            XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
            builder.setServiceName("192.168.1.60").setHost("192.168.1.60")
                    .setDebuggerEnabled(true)
                    .setPort(5222)
                    .setUsernameAndPassword(params[0], params[1])
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                    .setCompressionEnabled(false);
            config = builder.build();

            mConnection = new XMPPTCPConnection(config);
            try {
                //mConnection.setPacketReplyTimeout(10000);
                mConnection.addConnectionListener(connectionListener);
                mConnection.connect();
            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XMPPException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
}

这篇关于Smack 4.1 回复超时内无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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