XMPP client for Quickblox using Smack

怎甘沉沦 提交于 2019-12-13 18:59:11

问题


I'm trying to write a XMPP client to connect to Quickblox and use it as a bot for a chat application. I'm using Smack 4.1.3 for this purpose. Here's my code:

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();
    }

For some reason, I'm unable to make the client connect to a chat room using MultiUserChat. Here's the output when I run this code:

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

I turned on debugging and found this:

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>

The app configuration on quickblox seems correct as well. I've created a user that I'm using in this app. I've also created a public dialogue that is being used in this app as well. Not sure what's going on here.

Btw, I cannot use the SDKs provided with Quickblox since I've to deploy this code on my web server which is built on a java framework.


回答1:


improper-addressing error says what it says

This jid is strange 4461610-26179@chat.quickblox.com@chat.quickblox.com

it should be just 4461610-26179@chat.quickblox.com

that's why you receive this error

I don't see where it could be a problem with this in your code, anyway please check such a possibility



来源:https://stackoverflow.com/questions/31685667/xmpp-client-for-quickblox-using-smack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!