无法连接到ejabberd witch Android虚拟设备

时间:2018-10-03 21:34:46

标签: android xmpp ejabberd avd

我总是收到此错误消息:org.jivesoftware.smack.SmackException $ ConnectionException:以下地址失败:

这是我的代码

myButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Runnable runnable = new Runnable() {
                @Override
                public void run() {

                    XMPPTCPConnectionConfiguration connectionConfiguration = null;
                    try {

                        InetAddress addr = InetAddress.getByName("10.0.2.2");

                        DomainBareJid serviceName = JidCreate.domainBareFrom("10.0.2.2");

                        connectionConfiguration = XMPPTCPConnectionConfiguration.builder()
                                .setUsernameAndPassword("myusername", "mypassword")
                                .setXmppDomain(serviceName)
                                .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                                .setPort(5222)
                                .setHostAddress(addr)
                                .setDebuggerEnabled(true)
                                .build();
                    } catch (XmppStringprepException e) {
                        e.printStackTrace();
                    } catch (UnknownHostException e) {
                        e.printStackTrace();
                    }

                    AbstractXMPPConnection connection = null;
                    connection = new XMPPTCPConnection(connectionConfiguration);


                    try {
                        connection.connect().login();

                    } catch (XMPPException e) {
                        e.printStackTrace();
                    } catch (SmackException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            };
            Thread connectionThread = new Thread(runnable);
            connectionThread.start();
        }
    });

我也尝试过公开的玉host和不同的端口,但是什么也没做。

0 个答案:

没有答案