本文整理汇总了Java中org.jivesoftware.smack.Connection.addPacketListener方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.addPacketListener方法的具体用法?Java Connection.addPacketListener怎么用?Java Connection.addPacketListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.Connection
的用法示例。
在下文中一共展示了Connection.addPacketListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AgentRoster
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
* Constructs a new AgentRoster.
*
* @param connection an XMPP connection.
*/
AgentRoster(Connection connection, String workgroupJID) {
this.connection = connection;
this.workgroupJID = workgroupJID;
entries = new ArrayList<String>();
listeners = new ArrayList<AgentRosterListener>();
presenceMap = new HashMap<String, Map<String, Presence>>();
// Listen for any roster packets.
PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class);
connection.addPacketListener(new AgentStatusListener(), rosterFilter);
// Listen for any presence packets.
connection.addPacketListener(new PresencePacketListener(),
new PacketTypeFilter(Presence.class));
// Send request for roster.
AgentStatusRequest request = new AgentStatusRequest();
request.setTo(workgroupJID);
connection.sendPacket(request);
}
示例2: DeliveryReceiptManager
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
private DeliveryReceiptManager(Connection connection) {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
sdm.addFeature(DeliveryReceipt.NAMESPACE);
this.connection = connection;
instances.put(connection, this);
// register listener for delivery receipts and requests
connection.addPacketListener(this, new PacketExtensionFilter(DeliveryReceipt.NAMESPACE));
}
示例3: PingManager
import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
private PingManager(final Connection connection) {
this.connection = connection;
instances.put(connection, this);
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
sdm.addFeature(NAMESPACE);
PacketFilter pingPacketFilter = new PacketTypeFilter(Ping.class);
connection.addPacketListener(new PacketListener() {
/**
* Sends a Pong for every Ping
*/
public void processPacket(Packet packet) {
if (pingMinDelta > 0) {
// Ping flood protection enabled
long currentMillies = System.currentTimeMillis();
long delta = currentMillies - lastPingStamp;
lastPingStamp = currentMillies;
if (delta < pingMinDelta) {
return;
}
}
Pong pong = new Pong((Ping)packet);
connection.sendPacket(pong);
}
}
, pingPacketFilter);
connection.addConnectionListener(new ConnectionListener() {
@Override
public void connectionClosed() {
maybeStopPingServerTask();
}
@Override
public void connectionClosedOnError(Exception arg0) {
maybeStopPingServerTask();
}
@Override
public void reconnectionSuccessful() {
maybeSchedulePingServerTask();
}
@Override
public void reconnectingIn(int seconds) {
}
@Override
public void reconnectionFailed(Exception e) {
}
});
maybeSchedulePingServerTask();
}