您的位置:首页 > 运维架构

认识smack中的基本对象-Packet

2013-08-12 17:18 288 查看
一 对象介绍

Packet是XMPP中信息包的基类,所有存储信息的对象都要继承该类。每个Packet对象必须有一个唯一的ID号,该ID号有系统自动生成,不过也可以自己指定。其常见的字段有"to"、“from"等,Packet的每个属性都由一个键值对表示,键名为字符串类型,键值可以是java的原始类型,也可以是一个序列化的对象。

Base class for XMPP packets. Every packet has a unique ID (which is automatically generated, but can be overriden). Optionally, the "to" and "from" fields can be set, as well as an arbitrary number of properties. Properties provide
an easy mechanism for clients to share data. Each property has a String name, and a value that is a Java primitive (int, long, float, double, boolean) or any Serializable object (a Java object is Serializable when it implements the Serializable interface).

二 常用方法

1. 设置、获取Packet的ID。

getPacketID

public String getPacketID() Returns the unique ID of the packet. The returned value could be null when ID_NOT_AVAILABLE was set as the packet's id.

Returns:the packet's unique ID or null if the packet's id is not available.

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

setPacketID

public void setPacketID(String packetID) Sets the unique ID of the packet. To indicate that a packet has no id pass the constant ID_NOT_AVAILABLE as the packet's id value.

Parameters:packetID - the unique ID for the packet.

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

2. 设置、获取to属性,to属性表示该packet将被发送给谁,该属性为可选值,所以可以为空。

getTo

public String getTo() Returns who the packet is being sent "to", or null if the value is not set. The XMPP protocol often makes the "to" attribute optional, so it does not always need to be set.

The StringUtils class provides several useful methods for dealing with XMPP addresses such as parsing the bare address, user name, server, and resource.

Returns:who the packet is being sent to, or null if the value has not been set.

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

setTo

public void setTo(String to) Sets who the packet is being sent "to". The XMPP protocol often makes the "to" attribute optional, so it does not always need to be set.

Parameters:to - who the packet is being sent to.

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

3. 设置、获取from属性,from属性表示该packet是由谁发送的,该属性为可选值,所以可以为空。

getFrom

public String getFrom() Returns who the packet is being sent "from" or null if the value is not set. The XMPP protocol often makes the "from" attribute optional, so it does not always need to be set.

The StringUtils class provides several useful methods for dealing with XMPP addresses such as parsing the bare address, user name, server, and resource.

Returns:who the packet is being sent from, or null if the value has not been set.

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

setFrom

public void setFrom(String from) Sets who the packet is being sent "from". The XMPP protocol often makes the "from" attribute optional, so it does not always need to be set.

Parameters:from - who the packet is being sent to.

原文地址:http://www.igniterealtime.org/builds/smack/docs/3.2.2/javadoc/index.html?org/jivesoftware/smack/AccountManager.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenFire