无法使用 java 中的 smack 库使用 xmpp 服务器登录

Posted

技术标签:

【中文标题】无法使用 java 中的 smack 库使用 xmpp 服务器登录【英文标题】:Cannot log in with xmpp server using smack library in java 【发布时间】:2013-01-05 11:54:59 【问题描述】:

我开发 xmpp 服务器和客户端应用程序 smack 库。并且服务器/客户端之间的连接很容易建立,但是当我调用 'connection.login (user,password)' 函数时,会发生以下异常。

SASL 身份验证 PLAIN 失败:编码不正确:

at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:337)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)
at org.jivesoftware.smack.Connection.login(Connection.java:348)
at com.test.Client1Gui.connect(Client1Gui.java:86)
at com.test.Client1Gui$1.actionPerformed(Client1Gui.java:52)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

【问题讨论】:

【参考方案1】:

试试这个代码:

SASLAuthentication.supportSASLMechanism("PLAIN");
config.setSASLAuthenticationEnabled(true);

【讨论】:

以上是关于无法使用 java 中的 smack 库使用 xmpp 服务器登录的主要内容,如果未能解决你的问题,请参考以下文章

如何在 java 中使用 Smack XMPP 库处理 TLS 证书

如何使用 Smack XMPP 库创建 SSL 连接?

无法使用教程“使用 Smack 实现基于 XMPP 的应用服务器的 Java 示例”

java smack 4.0.3库facebook登录错误

线程“主”java.lang.NoSuchFieldError 中的异常:如果可能

无法在 JAVA 中使用 SMACK api 显示收到的消息