/** * 加入聊天室 * @param xmppConnection * @param roomName * @param password * @return */ public static MultiUserChat joinMultiUserChat(XMPPConnection xmppConnection,String roomName,String password,PacketListener packetListener){ try { // 使用XMPPConnection创建一个MultiUserChat窗口 MultiUserChat muc = new MultiUserChat(xmppConnection, roomName+ "@conference." + xmppConnection.getServiceName()); // 聊天室服务将会决定要接受的历史记录数量 DiscussionHistory history = new DiscussionHistory(); history.setMaxChars(0); // 用户加入聊天室 muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout()); if(packetListener!=null){ muc.addMessageListener(packetListener); } return muc; } catch (XMPPException e) { e.printStackTrace(); return null; } }
/** * 加入聊天室 * @param xmppConnection * @param roomName * @param password * @param packetListener 消息监听器 * @return */ public static MultiUserChat joinMultiUserChat(XMPPConnection xmppConnection,String roomName,String password,PacketListener packetListener){ try { // 使用XMPPConnection创建一个MultiUserChat窗口 MultiUserChat muc = new MultiUserChat(xmppConnection, roomName+ "@conference." + xmppConnection.getServiceName()); // 聊天室服务将会决定要接受的历史记录数量 DiscussionHistory history = new DiscussionHistory(); history.setMaxChars(0); // history.setSince(new Date()); // 用户加入聊天室 muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout()); Log.i("MultiUserChat", "会议室【"+roomName+"】加入成功........"); if(packetListener!=null){ muc.addMessageListener(packetListener); } return muc; } catch (XMPPException e) { Log.e("MultiUserChat", "会议室【"+roomName+"】加入失败........"); e.printStackTrace(); return null; } }
/** * The constructor for the XMPP bot. * * @param host * The server the bot should login. * @param port * The hosts port. * @param login * The bots login name. * @param password * The bots login password. * @param resource * The bots resource (i.e. Work or Home). Can be null. * @throws IllegalArgumentException * Throws an {@link IllegalArgumentException} if some of the parameters are in an * invalid format. */ public XMPPConnector(String host, String port, String login, String password, String resource) throws IllegalArgumentException { checkParameters(host, port, login, password, resource); int numericalPort = port == null ? DEFAULT_XMPP_PORT : Integer.parseInt(port); this.sender = login + "@" + host + "/" + resource; SmackConfiguration.DEBUG_ENABLED = Boolean.parseBoolean(ApplicationPropertyXmpp.DEBUG .getValue()); ProviderManager.addExtensionProvider(AliasPacketExtension.ALIAS_ELEMENT_NAME, AliasPacketExtension.ALIAS_NAMESPACE, AliasPacketExtension.class); ConnectionConfiguration config = new ConnectionConfiguration(host, numericalPort); connection = new XMPPTCPConnection(config); connect(login, password, resource); sendPriorityPresence(); if (connection.isConnected()) { LOG.info(ResourceBundleManager.instance().getText("xmpp.connection.started", Locale.ENGLISH)); connection.addConnectionListener(new XMPPConnectionStatusLogger()); } else { LOG.info("The XMPP connection wasn't established."); } }
@Override public List<Exception> initialize() { if (SystemUtil.onAndroid()) { // @formatter:off throw new RuntimeException( "You need to remove the smack-java7 dependency/jar from your build, " + "as it does not run on Android. " + "Use smack-android instead."); // @formatter:on } SmackConfiguration.setDefaultHostnameVerifier(new Java7HostnameVerifier()); Base64.setEncoder(Java7Base64Encoder.getInstance()); Base64UrlSafeEncoder.setEncoder(Java7Base64UrlSafeEncoder.getInstance()); DNSUtil.setIdnaTransformer(new StringTransformer() { @Override public String transform(String string) { return java.net.IDN.toASCII(string); } }); return null; }
@Test (expected=SmackException.class) public void getConfigFormWithTimeout() throws XMPPException, SmackException { ThreadedDummyConnection con = new ThreadedDummyConnection(); PubSubManager mgr = new PubSubManager(con); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); SmackConfiguration.setDefaultPacketReplyTimeout(100); con.setTimeout(); node.getNodeConfiguration(); }
/** * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if * no configuration is possible. The configuration form allows to set the room's language, * enable logging, specify room's type, etc.. * * @return the Form that contains the fields to complete together with the instrucions or * <tt>null</tt> if no configuration is possible. * @throws XMPPException if an error occurs asking the configuration form for the room. */ public Form getConfigurationForm() throws XMPPException { MUCOwner iq = new MUCOwner(); iq.setTo(room); iq.setType(IQ.Type.GET); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Request the configuration form to the server. connection.sendPacket(iq); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } return Form.getFormFrom(answer); }
/** * Sends the completed configuration form to the server. The room will be configured * with the new settings defined in the form. If the form is empty then the server * will create an instant room (will use default configuration). * * @param form the form with the new settings. * @throws XMPPException if an error occurs setting the new rooms' configuration. */ public void sendConfigurationForm(Form form) throws XMPPException { MUCOwner iq = new MUCOwner(); iq.setTo(room); iq.setType(IQ.Type.SET); iq.addExtension(form.getDataFormToSend()); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send the completed configuration form to the server. connection.sendPacket(iq); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } }
/** * Returns the room's registration form that an unaffiliated user, can use to become a member * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the * privilege to register members and allow only room admins to add new members.<p> * * If the user requesting registration requirements is not allowed to register with the room * (e.g. because that privilege has been restricted), the room will return a "Not Allowed" * error to the user (error code 405). * * @return the registration Form that contains the fields to complete together with the * instrucions or <tt>null</tt> if no registration is possible. * @throws XMPPException if an error occurs asking the registration form for the room or a * 405 error if the user is not allowed to register with the room. */ public Form getRegistrationForm() throws XMPPException { Registration reg = new Registration(); reg.setType(IQ.Type.GET); reg.setTo(room); PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } return Form.getFormFrom(result); }
/** * Sends the completed registration form to the server. After the user successfully submits * the form, the room may queue the request for review by the room admins or may immediately * add the user to the member list by changing the user's affiliation from "none" to "member.<p> * * If the desired room nickname is already reserved for that room, the room will return a * "Conflict" error to the user (error code 409). If the room does not support registration, * it will return a "Service Unavailable" error to the user (error code 503). * * @param form the completed registration form. * @throws XMPPException if an error occurs submitting the registration form. In particular, a * 409 error can occur if the desired room nickname is already reserved for that room; * or a 503 error can occur if the room does not support registration. */ public void sendRegistrationForm(Form form) throws XMPPException { Registration reg = new Registration(); reg.setType(IQ.Type.SET); reg.setTo(room); reg.addExtension(form.getDataFormToSend()); PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } }
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException { MUCOwner iq = new MUCOwner(); iq.setTo(room); iq.setType(IQ.Type.SET); // Set the new affiliation. MUCOwner.Item item = new MUCOwner.Item(affiliation); item.setJid(jid); iq.addItem(item); // Wait for a response packet back from the server. PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send the change request to the server. connection.sendPacket(iq); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } }
/** * Returns the collection that will contain the name of the shared groups where the user * logged in with the specified session belongs. * * @param connection connection to use to get the user's shared groups. * @return collection with the shared groups' name of the logged user. */ public static List getSharedGroups(Connection connection) throws XMPPException { // Discover the shared groups of the logged user SharedGroupsInfo info = new SharedGroupsInfo(); info.setType(IQ.Type.GET); // Create a packet collector to listen for a response. PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(info.getPacketID())); connection.sendPacket(info); // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results collector.cancel(); if (result == null) { throw new XMPPException("No response from the server."); } if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } return ((SharedGroupsInfo) result).getGroups(); }
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException { AgentWorkgroups request = new AgentWorkgroups(agentJID); request.setTo(serviceJID); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID())); // Send the request connection.sendPacket(request); AgentWorkgroups response = (AgentWorkgroups)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return response.getWorkgroups(); }
/** * Return the agents name. * * @return - the agents name. */ public String getName() throws XMPPException { AgentInfo agentInfo = new AgentInfo(); agentInfo.setType(IQ.Type.GET); agentInfo.setTo(workgroupJID); agentInfo.setFrom(getUser()); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID())); // Send the request connection.sendPacket(agentInfo); AgentInfo response = (AgentInfo)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return response.getName(); }
/** * Changes the name of the agent in the server. The server may have this functionality * disabled for all the agents or for this agent in particular. If the agent is not * allowed to change his name then an exception will be thrown with a service_unavailable * error code. * * @param newName the new name of the agent. * @throws XMPPException if the agent is not allowed to change his name or no response was * obtained from the server. */ public void setName(String newName) throws XMPPException { AgentInfo agentInfo = new AgentInfo(); agentInfo.setType(IQ.Type.SET); agentInfo.setTo(workgroupJID); agentInfo.setFrom(getUser()); agentInfo.setName(newName); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID())); // Send the request connection.sendPacket(agentInfo); IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return; }
/** * Returns the Form to use for searching transcripts. It is unlikely that the server * will change the form (without a restart) so it is safe to keep the returned form * for future submissions. * * @param serviceJID the address of the workgroup service. * @return the Form to use for searching transcripts. * @throws XMPPException if an error occurs while sending the request to the server. */ public Form getSearchForm(String serviceJID) throws XMPPException { TranscriptSearch search = new TranscriptSearch(); search.setType(IQ.Type.GET); search.setTo(serviceJID); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(search.getPacketID())); connection.sendPacket(search); TranscriptSearch response = (TranscriptSearch) collector.nextResult( SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return Form.getFormFrom(response); }
/** * Submits the completed form and returns the result of the transcript search. The result * will include all the data returned from the server so be careful with the amount of * data that the search may return. * * @param serviceJID the address of the workgroup service. * @param completedForm the filled out search form. * @return the result of the transcript search. * @throws XMPPException if an error occurs while submiting the search to the server. */ public ReportedData submitSearch(String serviceJID, Form completedForm) throws XMPPException { TranscriptSearch search = new TranscriptSearch(); search.setType(IQ.Type.GET); search.setTo(serviceJID); search.addExtension(completedForm.getDataFormToSend()); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(search.getPacketID())); connection.sendPacket(search); TranscriptSearch response = (TranscriptSearch) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return ReportedData.getReportedDataFrom(response); }
/** * Returns the full conversation transcript of a given session. * * @param sessionID the id of the session to get the full transcript. * @param workgroupJID the JID of the workgroup that will process the request. * @return the full conversation transcript of a given session. * @throws XMPPException if an error occurs while getting the information. */ public Transcript getTranscript(String workgroupJID, String sessionID) throws XMPPException { Transcript request = new Transcript(sessionID); request.setTo(workgroupJID); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID())); // Send the request connection.sendPacket(request); Transcript response = (Transcript) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return response; }
/** * Returns the transcripts of a given user. The answer will contain the complete history of * conversations that a user had. * * @param userID the id of the user to get his conversations. * @param workgroupJID the JID of the workgroup that will process the request. * @return the transcripts of a given user. * @throws XMPPException if an error occurs while getting the information. */ public Transcripts getTranscripts(String workgroupJID, String userID) throws XMPPException { Transcripts request = new Transcripts(userID); request.setTo(workgroupJID); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID())); // Send the request connection.sendPacket(request); Transcripts response = (Transcripts) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return response; }
/** * Returns the form for all search fields supported by the search service. * * @param con the current Connection. * @param searchService the search service to use. (ex. search.jivesoftware.com) * @return the search form received by the server. * @throws org.jivesoftware.smack.XMPPException * thrown if a server error has occurred. */ public Form getSearchForm(Connection con, String searchService) throws XMPPException { UserSearch search = new UserSearch(); search.setType(IQ.Type.GET); search.setTo(searchService); PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID())); con.sendPacket(search); IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return Form.getFormFrom(response); }
/** * Sends the filled out answer form to be sent and queried by the search service. * * @param con the current Connection. * @param searchForm the <code>Form</code> to send for querying. * @param searchService the search service to use. (ex. search.jivesoftware.com) * @return ReportedData the data found from the query. * @throws org.jivesoftware.smack.XMPPException * thrown if a server error has occurred. */ public ReportedData sendSearchForm(Connection con, Form searchForm, String searchService) throws XMPPException { UserSearch search = new UserSearch(); search.setType(IQ.Type.SET); search.setTo(searchService); search.addExtension(searchForm.getDataFormToSend()); PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID())); con.sendPacket(search); IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { return sendSimpleSearchForm(con, searchForm, searchService); } return ReportedData.getReportedDataFrom(response); }
Packet initiateIncomingStream(Connection connection, StreamInitiation initiation) throws XMPPException { StreamInitiation response = createInitiationAccept(initiation, getNamespaces()); // establish collector to await response PacketCollector collector = connection .createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID())); connection.sendPacket(response); Packet streamMethodInitiation = collector .nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (streamMethodInitiation == null) { throw new XMPPException("No response from file transfer initiator"); } return streamMethodInitiation; }
/** * Deletes the specified list of offline messages. The request will include the list of * stamps that uniquely identifies the offline messages to delete. * * @param nodes the list of stamps that uniquely identifies offline message. * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public void deleteMessages(List<String> nodes) throws XMPPException { OfflineMessageRequest request = new OfflineMessageRequest(); for (String node : nodes) { OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node); item.setAction("remove"); request.addItem(item); } // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(request.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send the deletion request to the server. connection.sendPacket(request); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } }
/** * Deletes all offline messages of the user. * * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public void deleteMessages() throws XMPPException { OfflineMessageRequest request = new OfflineMessageRequest(); request.setPurge(true); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(request.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send the deletion request to the server. connection.sendPacket(request); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } }
/** * Save this vCard for the user connected by 'connection'. Connection should be authenticated * and not anonymous.<p> * <p/> * NOTE: the method is asynchronous and does not wait for the returned value. * * @param connection the Connection to use. * @throws XMPPException thrown if there was an issue setting the VCard in the server. */ public void save(Connection connection) throws XMPPException { checkAuthenticated(connection, true); setType(IQ.Type.SET); setFrom(connection.getUser()); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID())); connection.sendPacket(this); Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } }
private void doLoad(Connection connection, String user) throws XMPPException { setType(Type.GET); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(getPacketID())); connection.sendPacket(this); VCard result = null; try { result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (result == null) { String errorMessage = "Timeout getting VCard information"; throw new XMPPException(errorMessage, new XMPPError( XMPPError.Condition.request_timeout, errorMessage)); } if (result.getError() != null) { throw new XMPPException(result.getError()); } } catch (ClassCastException e) { System.out.println("No VCard for " + user); } copyFieldsFrom(result); }
/** * Retrieve the last activity of a particular jid. * @param con the current Connection. * @param jid the JID of the user. * @return the LastActivity packet of the jid. * @throws XMPPException thrown if a server error has occured. * @deprecated This method only retreives the lapsed time since the last logout of a particular jid. * Replaced by {@link org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String) getLastActivity} */ public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException { LastActivity activity = new LastActivity(); jid = StringUtils.parseBareAddress(jid); activity.setTo(jid); PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID())); con.sendPacket(activity); LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { throw new XMPPException("No response from server on status set."); } if (response.getError() != null) { throw new XMPPException(response.getError()); } return response; }
/** * Returns the collection that will contain the name of the shared groups where the user * logged in with the specified session belongs. * * @param connection connection to use to get the user's shared groups. * @return collection with the shared groups' name of the logged user. */ public static List<String> getSharedGroups(Connection connection) throws XMPPException { // Discover the shared groups of the logged user SharedGroupsInfo info = new SharedGroupsInfo(); info.setType(IQ.Type.GET); // Create a packet collector to listen for a response. PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(info.getPacketID())); connection.sendPacket(info); // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results collector.cancel(); if (result == null) { throw new XMPPException("No response from the server."); } if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } return ((SharedGroupsInfo) result).getGroups(); }
/** * Notify server to change the carbons state. This method blocks * some time until the server replies to the IQ and returns true on * success. * * You should first check for support using isSupportedByServer(). * * @param new_state whether carbons should be enabled or disabled * * @return true if the operation was successful */ public boolean setCarbonsEnabled(final boolean new_state) { if (enabled_state == new_state) return true; IQ setIQ = carbonsEnabledIQ(new_state); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(setIQ.getPacketID())); connection.sendPacket(setIQ); IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (result != null && result.getType() == IQ.Type.RESULT) { enabled_state = new_state; return true; } return false; }