我正在使用以下代码开发带有smack的Android聊天应用程序。这是我第一次使用该库,我遵循了文档中的步骤。
private void setConnection(final String user, final String password) {
new Thread() {
@Override
public void run() {
InetAddress addr = null;
try {
addr = InetAddress.getByName(Constants.OPENFIRE_DOMAIN_NAME);
} 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(Constants.OPENFIRE_DOMAIN_NAME);
} catch (XmppStringprepException e) {
e.printStackTrace();
}
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(user, password)
.setPort(5222)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setXmppDomain(serviceName)
.setHostnameVerifier(verifier)
.setHostAddress(addr)
.setDebuggerEnabled(true)
.build();
mConnection = new XMPPTCPConnection(config);
try {
mConnection.connect();
mConnection.login();
if (mConnection.isAuthenticated() && mConnection.isConnected()) {
Log.e("Chat Activity", "Auth done and connected successfully");
ChatManager chatManager = ChatManager.getInstanceFor(mConnection);
chatManager.addIncomingListener(new IncomingChatMessageListener() {
@Override
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
Log.e("Chat Activity","New message from " + from + ": " + message.getBody());
mMessages.add(new MessagesData("0", message.getBody(), Parse.getTimeStamp()));
configureRecyclerView(mMessages);
}
});
}
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
但是执行它时,它显示了以下异常。
org.jivesoftware.smack.sasl.SASLErrorException: SASLError using SCRAM-SHA-1: not-authorized
我想知道代码中的错误可能是什么。感谢您的帮助