Ping协议就是利用约定的NameSpace任意IQ;

XMPP Ping

The XMPP Ping protocol is specified in XEP-0199 (a Draft Standard of the XMPP Standards Foundation). This specification defines an XMPP protocol extension for sending application-level pings over XML streams. Such pings can be sent from a client to a server, from one server to another, or end-to-end.

The following XML namespaces are used in the context of the XMPP Ping protocol:

urn:xmpp:pings

XEP-0199: XMPP Ping

Abstract: This specification defines an XMPP protocol extension for sending application-level pings over XML streams. Such pings can be sent from a client to a server, from one server to another, or end-to-end.
Author: Peter Saint-Andre
Copyright: ? 1999 - 2011 XMPP Standards Foundation. SEE LEGAL NOTICES.
Status: Final
Type: Standards Track
Version: 2.0
Last Updated: 2009-06-03
NOTICE: The protocol defined herein is a Final Standard of the XMPP Standards Foundation and can be considered a stable technology for implementation and deployment.

Table of Contents

1. Introduction
2. Requirements
3. Protocol
4. Use Cases
    4.1. Server-To-Client Pings
    4.2. Client-To-Server Pings
    4.3. Server-To-Server Pings
    4.4. Client-to-Client Pings
    4.5. Component-to-Client Pings
5. Determining Support
6. Implementation Notes
7. Security Considerations
8. IANA Considerations
9. XMPP Registrar Considerations
    9.1. Protocol Namespaces
10. XML Schema

Appendices
    A: Document Information
    B: Author Information
    C: Legal Notices
    D: Relation to XMPP
    E: Discussion Venue
    F: Requirements Conformance
    G: Notes
    H: Revision History

1. Introduction

As specified in XMPP Core [1], the XML streams used in XMPP are bound to TCP. Unfortunately, TCP connections can go down without the application (XMPP) layer knowing about it. The traditional approach to solving this issue has been to periodically send so-called "whitespace pings" over the XML stream. This document recommends a more XML-friendly approach, which can be used over more than one hop in the communication path (e.g., from one client to another) and can also be used with other bindings such as the BOSH [2] method for which XMPP Over BOSH [3] is the XMPP profile.

2. Requirements

This specification addresses the following requirements:

Determining the viability of an XML stream (i.e., its underlying binding) between a client and a server, or between two servers.
Determining end-to-end connectivity between any two XMPP entities (e.g., two clients).
The number of "hops" for which the ping tests connectivity depends on how far the pinged entity is from the pinging entity, as shown in the following use cases. However, this specification does not provide per-hop information similar to that provided by the traceroute protocol (RFC 1393 [4]); a future specification may define such functionality for XMPP.

3. Protocol

The XMPP ping protocol is extremely simple:

The pinging entity sends an IQ-get containing a <ping/> element qualified by the 'urn:xmpp:ping' namespace.
The pinged entity returns either an IQ-result (if it supports the namespace) or an IQ-error (if it does not).
4. Use Cases

4.1 Server-To-Client Pings

One popular usage is for a server to test the viability of the underlying stream connection by pinging a connected client. This is done by sending an <iq/> get over the stream from the server to the client.

Example 1. Ping

<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>
    
If the client supports the ping namespace, it MUST return an IQ-result, which functions as a "pong":

Example 2. Pong

<iq from='juliet@capulet.lit/balcony' to='capulet.lit' id='s2c1' type='result'/>
    
If the client does not support the ping namespace, it MUST return a <service-unavailable/> error:

Example 3. Ping Not Supported

<iq from='juliet@capulet.lit/balcony' to='capulet.lit' id='s2c1' type='error'>
  <ping xmlns='urn:xmpp:ping'/>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
    
The other error conditions defined in RFC 6120 could also be returned if appropriate.

4.2 Client-To-Server Pings

A client may also ping its server by sending an IQ-get over the stream between the two entities.

Example 4. Ping

<iq from='juliet@capulet.lit/balcony' to='capulet.lit' id='c2s1' type='get'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>
    
Note: The client MAY include a 'to' address of the client's bare JID <localpart@domain.tld>, in this instance "juliet@capulet.lit" or MAY include no 'to' address (this signifies that the stanza shall be handled by the server on behalf of the connected user's bare JID, which in the case of <iq/> stanzas is equivalent to directing the IQ-get to the server itself).

If the server supports the ping namespace, it MUST return an IQ-result:

Example 5. Pong

<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='c2s1' type='result'/>
    
If the server does not support the ping namespace, it MUST return a <service-unavailable/> error:

Example 6. Ping Not Supported

<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='c2s1' type='error'>
  <ping xmlns='urn:xmpp:ping'/>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
    
The other error conditions defined in RFC 6120 could also be returned if appropriate.

4.3 Server-To-Server Pings

Pings can also be used to test a server-to-server connection. This is done by sending an IQ-get over the stream from one server to another.

Example 7. Ping

<iq from='capulet.lit' to='montague.lit' id='s2s1' type='get'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>
    
If the other party to the stream supports the ping namespace, it MUST return an IQ-result:

Example 8. Pong

<iq from='montague.lit' to='capulet.lit' id='s2s1' type='result'/>
    
If the other party to the stream does not support the ping namespace, it MUST return a <service-unavailable/> error:

Example 9. Ping Not Supported

<iq from='montague.lit' to='capulet.lit' id='s2s1' type='error'>
  <ping xmlns='urn:xmpp:ping'/>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
    
The other error conditions defined in RFC 6120 could also be returned if appropriate.

4.4 Client-to-Client Pings

Pings can also be used for client-to-client (i.e., end-to-end) pings.

Example 10. Ping

<iq from='romeo@montague.lit/home' 
    to='juliet@capulet.lit/chamber'
    type='get' 
    id='e2e1'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>
    
Note: The 'to' address should be a full JID <localpart@domain.tld/resource>, since a ping sent to a bare JID <localpart@domain.tld> will be handled by the server on behalf of the client.

If the pinged entity supports the ping namespace, it SHOULD return an IQ-result:

Example 11. Pong

<iq from='juliet@capulet.lit/chamber'
    to='romeo@montague.lit/home' 
    id='e2e1'
    type='result'/>
    
If the pinged entity does not support the ping namespace, it MUST return a <service-unavailable/> error:

Example 12. Ping Not Supported

<iq from='juliet@capulet.lit/chamber'
    to='romeo@montague.lit/home' 
    id='e2e1'
    type='result'>
  <ping xmlns='urn:xmpp:ping'/>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
    
The other error conditions defined in RFC 6120 could also be returned if appropriate.

4.5 Component-to-Client Pings

Pings can also be used for component-to-client pings, for example from a Multi-User Chat [5] component to a client.

Example 13. Ping

<iq from='chat.shakespeare.lit'
    to='juliet@capulet.lit/chamber'
    type='get' 
    id='comp1'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>
    
Note: The 'to' address should be a full JID <localpart@domain.tld/resource>, since a ping sent to a bare JID <localpart@domain.tld> will be handled by the server on behalf of the client.

If the pinged entity supports the ping namespace, it SHOULD return an IQ-result:

Example 14. Pong

<iq from='juliet@capulet.lit/chamber'
    to='chat.shakespeare.lit'
    id='comp1'
    type='result'/>
    
If the pinged entity does not support the ping namespace, RFC 6120 requires it to return a <service-unavailable/> error:

Example 15. Ping Not Supported

<iq from='juliet@capulet.lit/chamber'
    to='chat.shakespeare.lit'
    id='comp1'
    type='error'>
  <ping xmlns='urn:xmpp:ping'/>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
    
The other error conditions defined in RFC 6120 could also be returned if appropriate.

5. Determining Support

If an entity supports the XMPP Ping protocol, it MUST report that fact by including a service discovery feature of "urn:xmpp:ping" in response to a Service Discovery [6] information request:

Example 16. Service Discovery information request

<iq type='get'
    from='juliet@capulet.lit/balcony'
    to='capulet.lit'
    id='disco1'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
  
Example 17. Service Discovery information response

<iq type='result'
    from='capulet.lit'
    to='juliet@capulet.lit/balcony'
    id='disco1'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    ...
    <feature var='urn:xmpp:ping'/>
    ...
  </query>
</iq>
  
In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined in Entity Capabilities [7]. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.

6. Implementation Notes

Some XMPP clients do not respond to IQ stanzas containing unsupported payloads. Although this is in violation of XMPP Core [8], this behavior can result in disconnection of clients that are in fact actively connected to the server.

7. Security Considerations

If a server receives a ping request directed to a full JID <localpart@domain.tld/resource> associated with a registered account but there is no connected resource matching the 'to' address, RFC 6120 requires it to reply with a <service-unavailable/> error and set the 'from' address of the IQ-error to the full JID provided in the 'to' address of the ping request. If a connected resource receives a ping request but it does not want to reveal its network availability to the sender for any reason (e.g., because the sender is not authorized to know the connected resource's availability), then it too MUST reply with a <service-unavailable/> error. This consistency between the server response and the client response helps to prevent presence leaks.

8. IANA Considerations

No interaction with the Internet Assigned Numbers Authority (IANA) [9] is necessary as a result of this document.

9. XMPP Registrar Considerations

9.1 Protocol Namespaces

The XMPP Registrar [10] includes "urn:xmpp:ping" in its registry of protocol namespaces (see <http://xmpp.org/registrar/namespaces.html>).

10. XML Schema

<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:xmpp:ping'
    xmlns='urn:xmpp:ping'
    elementFormDefault='qualified'>

<xs:annotation>
    <xs:documentation>
      The protocol documented by this schema is defined in
      XEP-0199: http://www.xmpp.org/extensions/xep-0199.html
    </xs:documentation>
  </xs:annotation>

<xs:element name='ping' type='empty'/>

<xs:simpleType name='empty'>
    <xs:restriction base='xs:string'>
      <xs:enumeration value=''/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
  
Appendices

Appendix A: Document Information

Series: XEP
Number: 0199
Publisher: XMPP Standards Foundation
Status: Final
Type: Standards Track
Version: 2.0
Last Updated: 2009-06-03
Approving Body: XMPP Council
Dependencies: XMPP Core, XEP-0030
Supersedes: None
Superseded By: None
Short Name: ping
Schema: <http://www.xmpp.org/schemas/ping.xsd>
Source Control: HTML
This document in other formats: XML  PDF

Appendix B: Author Information

Peter Saint-Andre

Email: stpeter@jabber.org
JabberID: stpeter@jabber.org
URI: https://stpeter.im/

Appendix C: Legal Notices

Copyright

This XMPP Extension Protocol is copyright ? 1999 - 2011 by the XMPP Standards Foundation (XSF).
Permissions

Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.
Disclaimer of Warranty

## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##
Limitation of Liability

In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.
IPR Conformance

This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at <http://xmpp.org/extensions/ipr-policy.shtml> or obtained by writing to XMPP Standards Foundation, 1899 Wynkoop Street, Suite 600, Denver, CO 80202 USA).
Appendix D: Relation to XMPP

The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 3920) and XMPP IM (RFC 3921) specifications contributed by the XMPP Standards Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.

Appendix E: Discussion Venue

The primary venue for discussion of XMPP Extension Protocols is the <standards@xmpp.org> discussion list.

Discussion on other xmpp.org discussion lists might also be appropriate; see <http://xmpp.org/about/discuss.shtml> for a complete list.

Errata can be sent to <editor@xmpp.org>.

Appendix F: Requirements Conformance

The following requirements keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".

Appendix G: Notes

1. RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core <http://tools.ietf.org/html/rfc6120>.

2. XEP-0124: Bidirectional-streams Over Synchronous HTTP <http://xmpp.org/extensions/xep-0124.html>.

3. XEP-0206: XMPP Over BOSH <http://xmpp.org/extensions/xep-0206.html>.

4. RFC 1393: Traceroute Using an IP Option <http://tools.ietf.org/html/rfc1393>.

5. XEP-0045: Multi-User Chat <http://xmpp.org/extensions/xep-0045.html>.

6. XEP-0030: Service Discovery <http://xmpp.org/extensions/xep-0030.html>.

7. XEP-0115: Entity Capabilities <http://xmpp.org/extensions/xep-0115.html>.

8. RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core <http://tools.ietf.org/html/rfc6120>.

9. The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see <http://www.iana.org/>.

10. The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see <http://xmpp.org/registrar/>.

Appendix H: Revision History

Note: Older versions of this specification might be available at http://xmpp.org/extensions/attic/

Version 2.0 (2009-06-03)

Per a vote of the XMPP Council, advanced status to Final.

(psa)
Version 1.0 (2007-06-12)

Per a vote of the XMPP Council, advanced status to Draft; XMPP Registrar issued urn:xmpp:ping namespace.

(psa)
Version 0.5 (2007-05-30)

Clarified error handling and recommended against sending to bare JIDs.

(psa)
Version 0.4 (2007-05-21)

Modified security considerations to ensure coherence of error handling between client and server.

(psa)
Version 0.3 (2007-05-07)

Added use case for client pinging server; changed namespace to conform to XMPP Registrar requirements, with namespace to be issued upon advancement to Draft; added section on discovering support.

(psa)
Version 0.2 (2006-11-22)

Changed IQ-set to IQ-get; clarified requirements; specified protocol description; added use cases.

(psa)
Version 0.1 (2006-11-21)

Initial version.

(psa)
END

XEP-0199: XMPP Ping相关推荐

  1. xmpp整理笔记:xmppFramework框架的导入和介绍

    一个将要开发xmpp的项目,建议在项目刚创建就导入框架,这样可以避免一些自己操作失误造成不必要的损失. xmpp中最常用的框架就是 xmppFrameWork 往期回顾: xmpp整理笔记:环境的快速 ...

  2. iOS —— XMPP 详解

    iOS - XMPP 的使用 转载 https://www.cnblogs.com/QianChia/p/6411914.html 1.XMPP XMPP 是一个基于 Socket 通信的即时通讯的协 ...

  3. Openfire XMPP Smack RTC IM 即时通讯 聊天 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  4. XMPPFrameWork IOS 开发(一)xmpp简介

    原始地址:XMPPFrameWork IOS 开发(一) XMPP : The Extensible Messaging and Presence Protocol 中文全称: 可扩展通讯和表示协议 ...

  5. 基于XMPP的即时通信系统的建立(二)— XMPP详解

    XMPP详解 XMPP(eXtensible Messaging and Presence Protocol,可扩展消息处理和现场协议)是一种在两个地点间传递小型结构化数据的协议.在此基础上,XMPP ...

  6. XMPP协议包文备注

    openfire服务器 android客户端Liu 和pc端zhuaizc 用户离线通知 <presence id="o32WV-45" type="unavail ...

  7. xmpp协议(即时通信协议规范)

    转载自 https://www.cnblogs.com/jiyuqi/p/5085932.html 相关背景 IM(Instant Messaging)正在被广泛使用,特别是公司与它们的客户互动连接方 ...

  8. openfire ping的smack解决方案(维持在线状态)

    连接中关联如下: Java代码   // iq提供者 roviderManager.getInstance().addIQProvider("ping", "urn:xm ...

  9. Log保存文件-Android

    为什么80%的码农都做不了架构师?>>>    前言 在开发过程中尤其是项目进入测试后,为了方便定位问题,经常需要将log保存下来,当然你可以自己写个log辅助类又或者直接使用第三方 ...

最新文章

  1. 你的Windows电脑里有哪些效率翻倍的生产力软件?
  2. 在 C# 中 (x == X) 何时成立?
  3. redis高并发原理_Java中的42行代码中的URL缩短服务— Java(?!)Spring Boot + Redis...
  4. 每日一皮:完美的结对编程!
  5. Wisdom RESTClient支持自动化测试并可以生成API文档
  6. ubuntu 安装 CUDA、 cuDNN 的tips
  7. Python基础教程:为元组中的每一个元素命名
  8. Python:条件判断
  9. Linux 创建和删除目录命令mkdir、rmdir
  10. extjs6 mvvm_ZK 6中的MVVM初探
  11. Shell 脚本案例实战 [4]
  12. linux时间同步和登陆数据库shell脚本
  13. flutter的四种模式/application/plugin/package/module,flutter调用原生的方法
  14. 6.27java斗地主
  15. 微信开放平台、公众平台的区别
  16. 网络流精讲——最大流 包教包会
  17. PHP地图规划骑行路径,高德路径规划,自定义骑行路线(适用3D地图)
  18. H5 video 自动播放(autoplay)不生效解决方案
  19. 适合学龄前孩子看的动画片 小蜜蜂(蜂来乐)值得推荐
  20. 【DP】AGC012B Splatter Painting

热门文章

  1. 关于学习Java是应该是自学还是选择培训班
  2. APP界面设计之页面布局的22条基本原则
  3. 港大全面封杀ChatGPT!AI肆虐高校,作弊丑闻震惊全世界
  4. 抖音视频拼接怎么做?推荐一款高效实用的软件
  5. pycharm无法翻译问题解决
  6. 51单片机 (十五)AT24C02
  7. Container: Context Aggregation Network
  8. ubuntu下面 将汉字桌面、下载 换成 英文
  9. web前端字体居中_html里文字居中代码怎么写?_WEB前端开发,html,css
  10. 翻译土耳其语言去哪里比较好