当前位置: 首页>>代码示例>>Java>>正文


Java Ping类代码示例

本文整理汇总了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());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:26,代码来源:PingTest.java

示例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);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:22,代码来源:PingTest.java

示例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);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:22,代码来源:PingTest.java

示例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秒
}
 
开发者ID:victoryckl,项目名称:XmppTest,代码行数:21,代码来源:SmackImpl.java

示例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秒
}
 
开发者ID:misty-rain,项目名称:smartedu,代码行数:21,代码来源:SmackImpl.java

示例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);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:15,代码来源:PingTest.java

示例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();
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:7,代码来源:PingProvider.java

示例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();
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:55,代码来源:PingManager.java

示例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();
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:6,代码来源:PingProvider.java

示例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();
}
 
开发者ID:xtang,项目名称:asmack-mini,代码行数:51,代码来源:PingManager.java

示例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);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:13,代码来源:PingManager.java


注:本文中的org.jivesoftware.smackx.ping.packet.Ping类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。