簡體   English   中英

無法使用 smack-Android 在 openfire 中創建新用戶

[英]cannot create new user in openfire using smack-Android

我正在嘗試使用 smack 為 android 的即時消息應用程序創建一個新用戶,該用戶將存儲在 openfire 數據庫中,但每次我運行它時,用戶記錄都沒有顯示在 openfire 中

創建用戶活動

 private void setConnection() {

        // Create the configuration for this new connection

        //this function or code given in official documention give an error in openfire run locally to solve this error
        //first off firewall
        //then follow my steps

        new Thread() {
            @Override
            public void run() {

                InetAddress addr = null;
                try {
                    // inter your ip4address now checking it
                    addr = InetAddress.getByName("192.168.23.150");
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                }
                HostnameVerifier verifier = new HostnameVerifier() {
                    @Override
                    public boolean verify(String hostname, SSLSession session) {
                        return false;
                    }
                };
                DomainBareJid serviceName = null;
                try {
                    serviceName = JidCreate.domainBareFrom("localhost");
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                }
                XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                        .setUsernameAndPassword("admin","kalaBOOK98")
                        .setPort(9090)
                        .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                        .setXmppDomain(serviceName)
                        .setHostnameVerifier(verifier)
                        .setHostAddress(addr)
                        .setDebuggerEnabled(true)
                        .build();
                Log.v(TAG,"connection configured");
                mConnection = new XMPPTCPConnection(config);
                        //now send message and receive message code here
                        AccountManager accountManager = AccountManager.getInstance(mConnection);
                        try {
                            Log.v(TAG,"Creating new user");
                            accountManager.createAccount(Localpart.from(userId),userPassword);
                        } catch (SmackException.NoResponseException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (XMPPException.XMPPErrorException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (SmackException.NotConnectedException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (InterruptedException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (XmppStringprepException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        }
                    }

// Now we create the account:

// The account has been created, so we can now login

        }.start();
    }

每次我嘗試運行它時都會出現此日志錯誤

日志

    2018-11-30 18:44:16.186 12186-12855/com.example.user.myapplication V/SignupActivity: connection configured
2018-11-30 18:44:16.216 12186-12855/com.example.user.myapplication V/SignupActivity: Creating new user
2018-11-30 18:44:16.218 12186-12855/com.example.user.myapplication V/SignupActivity: Error in creating userorg.jivesoftware.smack.SmackException$NotConnectedException: Client is not, or no longer, connected.
2018-11-30 18:44:16.218 12186-12855/com.example.user.myapplication W/System.err: org.jivesoftware.smack.SmackException$NotConnectedException: Client is not, or no longer, connected.
2018-11-30 18:44:16.226 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection.throwNotConnectedExceptionIfAppropriate(XMPPTCPConnection.java:354)
2018-11-30 18:44:16.226 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:670)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smack.AbstractXMPPConnection.createStanzaCollectorAndSend(AbstractXMPPConnection.java:769)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.createStanzaCollectorAndSend(AccountManager.java:370)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.getRegistrationInfo(AccountManager.java:366)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.getAccountAttributes(AccountManager.java:184)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.createAccount(AccountManager.java:249)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at com.example.user.myapplication.Login.SignupActivity$3.run(SignupActivity.java:192)

任何幫助將不勝感激提前致謝

正如您在日志中看到的,您必須連接到服務器才能創建新用戶。 您的連接有問題,在重新連接成功之前您無法創建用戶。 您可以通過以下方法在創建用戶之前檢查您的連接或身份驗證狀態:

connection.isAuthenticated()
connection.isConnected()
mConnection = new XMPPTCPConnection(config);
//now send message and receive message code here
AccountManager accountManager = AccountManager.getInstance(mConnection);
try {
    accountManager.createAccount(Localpart.from(userId),userPassword);
} …

創建連接實例后,它未連接。 這就是為什么當您嘗試執行需要連接的操作時會收到NotConnectedException原因。 為了在您的 XMPP 服務上創建帳戶,您首先必須通過調用連接到服務

`mConnection.connect()`.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM