天天看點

認識smack中的基本對象-IQ

一 IQ類的介紹

IQ繼承自Packet,是Info/Query的縮寫,IQ是最基本的資訊查詢包,它被用于從伺服器擷取資訊,或将資訊設定到伺服器,包括認證、花名冊的操作、建立使用者等。每個IQ包對象都包含一個類型屬性,用于指定改資訊包的操作類型,取值為:get、set、result、error。

 The base IQ (Info/Query) packet. IQ packets are used to get and set information on the server, including authentication, roster operations, and creating accounts. Each IQ packet has a specific type that indicates what type of action is being taken: "get", "set", "result", or "error".

 IQ packets can contain a single child element that exists in a specific XML namespace. The combination of the element name and namespace determines what type of IQ packet it is. Some example IQ subpacket snippets:

•<query xmlns="jabber:iq:auth"> -- an authentication IQ.

•<query xmlns="jabber:iq:private"> -- a private storage IQ.

•<pubsub xmlns="http://jabber.org/protocol/pubsub"> -- a pubsub IQ.

 二 IQ類的靜态成員

IQ.Type,其可取的值如下:

  • IQ.Type.GET
  • IQ.Type.SET
  • IQ.Type.RESULT
  • IQ.Type.ERROR

二 IQ類的方法

getType

 public IQ.Type getType() Returns the type of the IQ packet.

Returns:the type of the IQ packet.

--------------------------------------------------------------------------------

setType

 public void setType(IQ.Type type) Sets the type of the IQ packet.

Parameters:type - the type of the IQ packet.