网站建设SEO优化,网络系统分类,济南高新区网站建设,怎么用虚拟主机做网站步骤### javasmackopenfire即时通讯Im(四) ###* 创建群聊* 加入群聊# 创建群聊 #前面的单聊完成以后#xff0c;就开始群聊的功能把#xff0c;首先是创建群聊#xff1a;后端进行群组创建#xff1a;/***** 方法名称#xff1a;createMutiUserChat* 概要说明#xff1a;创建…### javasmackopenfire即时通讯Im(四) ###* 创建群聊* 加入群聊# 创建群聊 #前面的单聊完成以后就开始群聊的功能把首先是创建群聊后端进行群组创建/***** 方法名称createMutiUserChat* 概要说明创建群聊** param userName* param password* param roomName* param roomDesc* return void** author ZhangYH* date 2020/06/17 10:18:08*/public static String createMutiUserChat(String userName, String password,String roomName,String roomDesc){//默认使用创建人用户名时间戳为房间IDString roomId userName_System.currentTimeMillis();try {XMPPTCPConnection connection initOpenfireConnect();connection.login(userName,password);//获取房间管理对象MultiUserChatManager manager MultiUserChatManager.getInstanceFor(connection);//创建一个房间MultiUserChat muc manager.getMultiUserChat(roomIdconference.OPENFIRE_SERVICE_NAME);muc.create(userName);// User1 (which is the room owner) configures the room as a moderated roomForm form muc.getConfigurationForm();Form answerForm form.createAnswerForm();//向提交的表单添加默认答复,获取房间的默认设置菜单for(FormField field : form.getFields() ){if(!FormField.Type.hidden.name().equals(field.getType()) field.getVariable() ! null) {answerForm.setDefaultAnswer(field.getVariable());}}//muc#//房间名称answerForm.setAnswer(FormField.FORM_TYPE, http://jabber.org/protocol/muc#roomconfig);//设置房间名称answerForm.setAnswer(muc#roomconfig_roomname,roomName);//设置房间描述answerForm.setAnswer(muc#roomconfig_roomdesc, roomDesc);//是否允许修改主题answerForm.setAnswer(muc#roomconfig_changesubject, true);//设置房间最大用户数List maxusers new ArrayList();maxusers.add(100);answerForm.setAnswer(muc#roomconfig_maxusers, maxusers);List cast_values new ArrayList();cast_values.add(moderator);cast_values.add(participant);cast_values.add(visitor);answerForm.setAnswer(muc#roomconfig_presencebroadcast, cast_values);//设置为公共房间answerForm.setAnswer(muc#roomconfig_publicroom, true);//设置为永久房间answerForm.setAnswer(muc#roomconfig_persistentroom, true);//允许修改昵称answerForm.setAnswer(x-muc#roomconfig_canchangenick, true);//允许用户登录注册房间answerForm.setAnswer(x-muc#roomconfig_registration, true);muc.sendConfigurationForm(answerForm);muc.join(userName);//关闭连接closeConnection(connection);return roomId;}catch (Exception e){e.printStackTrace();}return roomId;}# 加入群聊 #/***** 方法名称joinMultiUserChat* 概要说明加入群聊** param userName* param password* param roomId* return void** author ZhangYH* date 2020/06/17 10:30:28*/public static void joinMultiUserChat(String userName, String password, String roomId) {try {XMPPTCPConnection connection initOpenfireConnect();connection.login(userName,password);// 使用XMPPConnection创建一个MultiUserChat窗口MultiUserChatManager manager MultiUserChatManager.getInstanceFor(connection);//获取会议室信息MultiUserChat muc manager.getMultiUserChat(roomIdconference.OPENFIRE_SERVICE_NAME);// 聊天室服务将会决定要接受的历史记录数量DiscussionHistory history new DiscussionHistory();history.setMaxStanzas(0);//history.setSince(new Date());// 用户加入聊天室muc.join(userName, password, history, System.currentTimeMillis());System.out.println(群聊加入成功........);//关闭连接closeConnection(connection);}catch (Exception e){e.printStackTrace();}}注openfire的群聊机制是这样的建群的时候必须要设置群组信息持久化(answerForm.setAnswer(“muc\#roomconfig\_persistentroom”, true);)要不然过一段时间群聊会自动删除的还有就是添加成员进入群聊以后当成员下线以后会自动将下线的成员踢出群聊。