认识smack中的基本对象-Packet

一  对象介绍

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值