本文整理汇总了Java中org.jivesoftware.smackx.ping.packet.Ping类的典型用法代码示例。如果您正苦于以下问题:Java Ping类的具体用法?Java Ping怎么用?Java Ping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Ping类属于org.jivesoftware.smackx.ping.packet包,在下文中一共展示了Ping类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkProvider
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
@Test
public void checkProvider() throws Exception {
// @formatter:off
String control = "<iq from='capulet.lit' to='[email protected]/balcony' id='s2c1' type='get'>"
+ "<ping xmlns='urn:xmpp:ping'/>"
+ "</iq>";
// @formatter:on
DummyConnection con = new DummyConnection();
con.connect();
// Enable ping for this connection
PingManager.getInstanceFor(con);
IQ pingRequest = (IQ) PacketParserUtils.parseStanza(control);
assertTrue(pingRequest instanceof Ping);
con.processPacket(pingRequest);
Stanza pongPacket = con.getSentPacket();
assertTrue(pongPacket instanceof IQ);
IQ pong = (IQ) pongPacket;
assertEquals("capulet.lit", pong.getTo());
assertEquals("s2c1", pong.getStanzaId());
assertEquals(IQ.Type.result, pong.getType());
}
示例2: checkSuccessfulDiscoRequest
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
@Test
public void checkSuccessfulDiscoRequest() throws Exception {
ThreadedDummyConnection con = getAuthentiactedDummyConnection();
DiscoverInfo info = new DiscoverInfo();
info.addFeature(Ping.NAMESPACE);
//@formatter:off
String reply =
"<iq type='result' id='qrzSp-16' to='[email protected]'>" +
"<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" +
"<feature var='urn:xmpp:ping'/>" +
"</query></iq>";
//@formatter:on
IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSupported = pinger.isPingSupported("[email protected]");
assertTrue(pingSupported);
}
示例3: checkUnuccessfulDiscoRequest
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
@Test
public void checkUnuccessfulDiscoRequest() throws Exception {
ThreadedDummyConnection con = getAuthentiactedDummyConnection();
DiscoverInfo info = new DiscoverInfo();
info.addFeature(Ping.NAMESPACE);
//@formatter:off
String reply =
"<iq type='result' id='qrzSp-16' to='[email protected]'>" +
"<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" +
"<feature var='urn:xmpp:noping'/>" +
"</query></iq>";
//@formatter:on
IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSupported = pinger.isPingSupported("[email protected]");
assertFalse(pingSupported);
}
示例4: sendServerPing
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
@Override
public void sendServerPing() {
if (mPingID != null) {// 此时说明上一次ping服务器还未回应,直接返回,直到连接超时
L.d("Ping: requested, but still waiting for " + mPingID);
return; // a ping is still on its way
}
Ping ping = new Ping();
ping.setType(Type.GET);
ping.setTo(PreferenceUtils.getPrefString(mService,
PreferenceConstants.Server, PreferenceConstants.GMAIL_SERVER));
mPingID = ping.getPacketID();// 此id其实是随机生成,但是唯一的
mPingTimestamp = System.currentTimeMillis();
L.d("Ping: sending ping " + mPingID);
mXMPPConnection.sendPacket(ping);// 发送ping消息
// register ping timeout handler: PACKET_TIMEOUT(30s) + 3s
((AlarmManager) mService.getSystemService(Context.ALARM_SERVICE)).set(
AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ PACKET_TIMEOUT + 3000, mPongTimeoutAlarmPendIntent);// 此时需要启动超时判断的闹钟了,时间间隔为30+3秒
}
示例5: sendServerPing
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
@Override
public void sendServerPing() {
if (mPingID != null) {// 此时说明上一次ping服务器还未回应,直接返回,直到连接超时
AppLogger.d("Ping: requested, but still waiting for " + mPingID);
return; // a ping is still on its way
}
Ping ping = new Ping();
ping.setType(Type.GET);
ping.setTo(PreferenceUtils.getPrefString(mService,
PreferenceConstants.Server, PreferenceConstants.GMAIL_SERVER));
mPingID = ping.getPacketID();// 此id其实是随机生成,但是唯一的
mPingTimestamp = System.currentTimeMillis();
AppLogger.d("Ping: sending ping " + mPingID);
mXMPPConnection.sendPacket(ping);// 发送ping消息
// register ping timeout handler: PACKET_TIMEOUT(30s) + 3s
((AlarmManager) mService.getSystemService(Context.ALARM_SERVICE)).set(
AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ PACKET_TIMEOUT + 3000, mPongTimeoutAlarmPendIntent);// 此时需要启动超时判断的闹钟了,时间间隔为30+3秒
}
示例6: checkSendingPing
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
@Test
public void checkSendingPing() throws InterruptedException, SmackException, IOException, XMPPException {
DummyConnection dummyCon = getAuthentiactedDummyConnection();
PingManager pinger = PingManager.getInstanceFor(dummyCon);
try {
pinger.ping("[email protected]");
}
catch (SmackException e) {
// Ignore the fact the server won't answer for this unit test.
}
Stanza sentPacket = dummyCon.getSentPacket();
assertTrue(sentPacket instanceof Ping);
}
示例7: parse
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
@Override
public Ping parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
// No need to use the ping constructor with arguments. IQ will already
// have filled out all relevant fields ('from', 'to', 'id').
return new Ping();
}
示例8: PingManager
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的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();
}
示例9: parseIQ
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
public IQ parseIQ(XmlPullParser parser) throws Exception {
// No need to use the ping constructor with arguments. IQ will already
// have filled out all relevant fields ('from', 'to', 'id').
return new Ping();
}
示例10: init
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
private void init() {
periodicPingExecutorService = new ScheduledThreadPoolExecutor(1);
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) {
}
});
instances.put(connection, this);
maybeSchedulePingServerTask();
}
示例11: isPingSupported
import org.jivesoftware.smackx.ping.packet.Ping; //导入依赖的package包/类
/**
* Query the specified entity to see if it supports the Ping protocol (XEP-0199)
*
* @param jid The id of the entity the query is being sent to
* @return true if it supports ping, false otherwise.
* @throws XMPPErrorException An XMPP related error occurred during the request
* @throws NoResponseException if there was no response from the jid.
* @throws NotConnectedException
*/
public boolean isPingSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Ping.NAMESPACE);
}