我想写一XMPP客户端连接到Quickblox和使用它作为一个聊天应用程序一个机器人。 我使用的Smack 4.1.3用于这一目的。 这里是我的代码:
public static void sendChat1() {
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("4461610-26179", "pass")
.setServiceName("chat.quickblox.com")
.setPort(5222)
.build();
System.out.println("Establishing Connection");
AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
try {
conn2.connect();
} catch (SmackException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (IOException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (XMPPException e) {
System.out.println("ERROR");
e.printStackTrace();
}
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(conn2);
System.out.println("Creating multi user chat room");
MultiUserChat muc = manager.getMultiUserChat("26179_55b76303535c12544b00b550@muc.chat.quickblox.com");
System.out.println("Joining chat room");
try {
muc.join("4461610");
} catch (XMPPException.XMPPErrorException e) {
System.out.println("ERROR");
e.printStackTrace();
return;
} catch (SmackException e) {
System.out.println("ERROR");
e.printStackTrace();
return;
}
System.out.println("Chat room request");
try {
muc.sendConfigurationForm(new Form(DataForm.Type.submit));
} catch (SmackException.NoResponseException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
System.out.println("ERROR");
e.printStackTrace();
}
}
public static void main(String[] args) {
sendChat1();
}
出于某种原因,我无法使客户端连接到使用MultiUserChat聊天室。 下面是当我运行这段代码的输出:
Establishing Connection
Creating multi user chat room
Joining chat room
ERROR
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: not-authorized - auth
at org.jivesoftware.smack.XMPPException$XMPPErrorException.ifHasErrorThenThrow(XMPPException.java:135)
at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:232)
at org.jivesoftware.smackx.muc.MultiUserChat.enter(MultiUserChat.java:311)
at org.jivesoftware.smackx.muc.MultiUserChat.join(MultiUserChat.java:495)
at org.jivesoftware.smackx.muc.MultiUserChat.join(MultiUserChat.java:430)
at Main.sendChat1(Main.java:53)
at Main.main(Main.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Jul 29, 2015 12:52:36 AM org.jivesoftware.smack.roster.Roster$PresencePacketListener processPacket
WARNING: Roster not loaded while processing presence stanza
Process finished with exit code 0
我打开调试,发现这一点:
Establishing Connection
01:28:55 AM SENT (0): <stream:stream xmlns='jabber:client' to='chat.quickblox.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='4461610-26179@chat.quickblox.com@chat.quickblox.com' xml:lang='en'>
01:28:56 AM RECV (0): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='tigase-error-tigase' from='chat.quickblox.com' version='1.0' xml:lang='en'><stream:error><improper-addressing xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error></stream:stream>
在quickblox该应用程序的配置似乎是正确的为好。 我创建了我使用的是在此应用程序的用户。 我还创建了在此应用程序中使用,以及公众对话。 不知道是怎么回事。
顺便说一句,因为我已经到这是建立在Java框架,我的Web服务器上部署这个代码,我无法使用提供Quickblox的软件开发工具包。