Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多处理器XMPP asmack连接_Java_Xmpp_Openfire_Asmack - Fatal编程技术网

Java 多处理器XMPP asmack连接

Java 多处理器XMPP asmack连接,java,xmpp,openfire,asmack,Java,Xmpp,Openfire,Asmack,我是这个OpenFire和asmack的新手,我希望用户有一个多用户聊天的功能,所以我四处搜索,发现了很多我已经实现了创建一个房间并向其他用户发送邀请这些工作,其他用户收到了邀请,但其他用户无法加入房间 我在接收其他用户邀请时执行此操作 这里连接是这个用户的连接,房间是我们在邀请中得到的房间名称 MultiUserChat muc3=新的MultiUserChat(连接、聊天室) muc3.join(“testbot3”) testbot3只是一个随机名称 但这会抛出404错误。 我是否需要在发

我是这个OpenFire和asmack的新手,我希望用户有一个多用户聊天的功能,所以我四处搜索,发现了很多我已经实现了创建一个房间并向其他用户发送邀请这些工作,其他用户收到了邀请,但其他用户无法加入房间

我在接收其他用户邀请时执行此操作

这里连接是这个用户的连接,房间是我们在邀请中得到的房间名称

MultiUserChat muc3=新的MultiUserChat(连接、聊天室)

muc3.join(“testbot3”)

testbot3只是一个随机名称

但这会抛出404错误。

我是否需要在发送邀请之前加入用户,即如果用户向B发送邀请,则在发送邀请之前,A需要在默认情况下加入这些用户到房间,然后取决于B拒绝或保持安静

我所做的是B收到A的邀请,我正试图用上面的代码加入B的邀请者

我已经尝试了很长时间,现在我不知道是什么地方出了问题,有人可以给一个示例代码,如何做到这一点,这将是非常有帮助的我

谢谢

这是关于我的问题的更多信息


当我在Openfire上查看时,我可以看到用户创建的房间,他自己也被添加为所有者,所以我认为创建房间不会有问题

这可能是房间被锁定的问题,因为我已经通读了房间未完全创建时房间被锁定的信息,我想这是我们创建房间时表单填写的问题,我没有在表单中填写密码这可能是问题吗?

请在我调用的处理程序“checkInvitation”中查看下面的代码,该方法与上面发布的代码相同,但我得到404。你能告诉我我的代码错了什么吗。

需要添加的昵称可以是任何东西,也可以是用户特定的东西

公共聊天室(){


404错误表明:

404 error can occur if the room does not exist or is locked
因此,请确保您的房间未被锁定或不存在!下面的代码是我在收到邀请时加入房间的方式:

private void setChatRoomInvitationListener() {
    MultiUserChat.addInvitationListener(mXmppConnection,
            new InvitationListener() {

                @Override
                public void invitationReceived(Connection connection,
                        String room, String inviter, String reason,
                        String unKnown, Message message) {

                    //MultiUserChat.decline(mXmppConnection, room, inviter,
                        //  "Don't bother me right now");
                    // MultiUserChat.decline(mXmppConnection, room, inviter,
                    // "Don't bother me right now");
                    try {
                       muc.join("test-nick-name");
                       Log.e("abc","join room successfully");
                       muc.sendMessage("I joined this room!! Bravo!!");
                    } catch (XMPPException e) {
                       e.printStackTrace();
                       Log.e("abc","join room failed!");
                    }
                }
            });
}
希望这有助于你的错误

编辑:这是我配置文件室的方式:

 /*
         * Create room
         */
        muc.create(roomName);

        // muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
        Form form = muc.getConfigurationForm();
        Form submitForm = form.createAnswerForm();

        for (Iterator fields = form.getFields(); fields.hasNext();) {
            FormField field = (FormField) fields.next();
            if (!FormField.TYPE_HIDDEN.equals(field.getType())
                    && field.getVariable() != null) {
                show("field: " + field.getVariable());
                // Sets the default value as the answer
                submitForm.setDefaultAnswer(field.getVariable());
            }
        }

        List<String> owners = new ArrayList<String>();
        owners.add(DataConfig.USERNAME + "@" + DataConfig.SERVICE);
        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        submitForm.setAnswer("muc#roomconfig_roomname", roomName);
        submitForm.setAnswer("muc#roomconfig_persistentroom", true);

        muc.sendConfigurationForm(submitForm);
        // submitForm.
        show("created room!");
        muc.addMessageListener(new PacketListener() {
            @Override
            public void processPacket(Packet packet) {
                show(packet.toXML());
                Message mess = (Message) packet;
                showMessageToUI(mess.getFrom() + ": " + mess.getBody());
            }
        });
/*
*创造空间
*/
muc.create(roomName);
//muc.sendConfigurationForm(新表格(表格类型_提交));
Form Form=muc.getConfigurationForm();
Form submitForm=Form.createAnswerForm();
for(迭代器字段=form.getFields();fields.hasNext();){
FormField=(FormField)fields.next();
如果(!FormField.TYPE_HIDDEN.equals(field.getType())
&&field.getVariable()!=null){
显示(“字段:+field.getVariable());
//将默认值设置为答案
submitForm.setDefaultAnswer(field.getVariable());
}
}
列表所有者=新的ArrayList();
添加(DataConfig.USERNAME+“@”+DataConfig.SERVICE);
submitForm.setAnswer(“muc#roomconfig_roomowners”,所有者);
submitForm.setAnswer(“muc#roomconfig_roomname”,roomname);
submitForm.setAnswer(“muc#roomconfig_persistentroom”,true);
muc.sendConfigurationForm(submitForm);
//提交表格。
显示(“创建的房间!”);
addMessageListener(新的PacketListener(){
@凌驾
公共无效处理数据包(数据包){
show(packet.toXML());
消息mess=(消息)数据包;
showMessageToUI(mess.getFrom()+”:“+mess.getBody());
}
});

使用此配置,我可以轻松加入聊天室而无需密码。

您可以使用代码片段加入聊天:

public void joinMultiUserChatRoom(String userName, String roomName) {
        // Get the MultiUserChatManager
        MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);

        // Create a MultiUserChat using an XMPPConnection for a room
        MultiUserChat multiUserChat = manager.getMultiUserChat(roomName + "@conference.localhost");

        DiscussionHistory history = new DiscussionHistory();
        history.setMaxStanzas(-1);
        try {
            multiUserChat.join(userName, "", history, connection.getPacketReplyTimeout());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
邀请朋友:

 /**
     * Invites another user to this room.
     *
     * @param userAddress the address of the user to invite to the room.(one
     *   may also invite users not on their contact list).
     * @param reason a reason, subject, or welcome message that would tell
     *   the the user why they are being invited.
     */
    public void invite(String userAddress, String reason)
    {
        multiUserChat.invite(userAddress, reason);
    }

当我在Openfire上查看时,我可以看到该用户创建的房间,他已被添加为所有者,因此我不认为创建房间会有问题。您是否尝试过使用非房间所有者的用户帐户加入房间?Hi@Kingfisher我能够通过processPacket方法向房间中的用户发送消息每次我发送消息但在processPacket方法中未收到任何消息时都会调用。是否存在任何问题或我们需要设置任何其他侦听器???@KK_07k11A0585我认为您应该在
XmppConnection
对象中注册侦听器:
XmppConnection.addPacketListener(packetListener,null);
并且在
packetListener
中,您可以像这样检查收到的数据包的类型:
if(packetinstanceof org.jivesoftware.smack.packet.Message&((org.jivesoftware.smack.packet.Message)数据包)。getType().equals(type.groupchat))
。不要在
MUC
中注册,只需在
连接中注册即可。
@KK_07k11A0585:您应该仔细阅读此链接:。在配置房间时,有一个字段:``。您必须对其进行配置以接收所有历史信息!P/s:下次,请问另一个问题!你好@Doniv我能够向房间a中的用户发送消息nd每次我发送消息时都会调用processPacket方法,但在processPacket方法中我没有收到任何消息。是否存在任何问题或我们需要设置任何其他侦听器???
 /**
     * Invites another user to this room.
     *
     * @param userAddress the address of the user to invite to the room.(one
     *   may also invite users not on their contact list).
     * @param reason a reason, subject, or welcome message that would tell
     *   the the user why they are being invited.
     */
    public void invite(String userAddress, String reason)
    {
        multiUserChat.invite(userAddress, reason);
    }