Smack Openfire Android Unable to send message to Group/Room Error 403 forbidden

此生再无相见时 提交于 2019-12-11 06:20:53

问题


MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(xmppconnection.getConnection());
try {
    MultiUserChat muc = manager.getMultiUserChat("test2@conference.cca");

    muc.join("test2@conference.cca");

    Message msg = new Message("test2@conference.cca", Message.Type.groupchat);
    msg.setBody("Hi Testing..Group chat..");
    muc.sendMessage(msg);
    // muc.join("test", "1234");
} catch (SmackException.NotConnectedException e) {
    e.printStackTrace();
} catch (SmackException e) {
    e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
    e.printStackTrace();
} catch (XMPPException e) {
    e.printStackTrace();
}

Error is:

error code="403" type="auth" forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>**


回答1:


There are several errors, logical and procedurals.

With this invocation:

 MultiUserChat muc = manager.getMultiUserChat("test2@conference.cca");

you have in muc object your groupchat. So you need to check if you already joined this groupchat or double join will raise an exception.

so

if (!muc.isJoined())
 muc.join("My nickname");

more, when you join, you MUST provide an unique nickname per User to join, or you'll obtain an exception with the second user. Set as nickname the same name of the groupchat it's 99% a logical error.

Finally, to send a message, just send it through MUC object or you'll risk, like in this case, to miss some information.

So just send it with

muc.send("Hi Testing..Group chat..");

Last but not least: of course multiuserchat must exists or inititilized before properly, it's a prerequisite to do all this. As first step, just create it in Openfire with http-admin-panel (make it persistant)



来源:https://stackoverflow.com/questions/41140681/smack-openfire-android-unable-to-send-message-to-group-room-error-403-forbidden

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