XEP-0304: Whitespace Keepalive Negotiation

This specification defines a method for negotiating how to send keepalives in XMPP.
Ming Ji
© 2011 – 2011 XMPP Standards Foundation. SEE LEGAL NOTICES.


WARNING: This document has been automatically Deferred after 12 months of inactivity in its previous Experimental state. Implementation of the protocol described herein is not recommended for production systems. However, exploratory implementations are encouraged to resume the standards process.
Standards Track
0.1 (2011-08-18)
Document Lifecycle
  1. Experimental
  2. Deferred
  3. Proposed
  4. Stable
  5. Final

1. Introduction

RFC 6120 [1] specifies that XMPP servers and clients can send whitespace characters between first-level elements of an XML stream as a way to maintain the state of the stream. These "whitespace keepalives" are widely used on the XMPP network. However, currently it is not possible to negotiate the frequency of sending keepalives, or even whether to send keepalives at all (the server simply sends them according to its own schedule). Because certain kinds of devices might not want to use keepalives, or might wish to receive keepalives more frequently or less frequently than the server's default, this specification defines a method for negotiating how to send whitespace keepalives between an XMPP server and an XMPP client (this method could also be used between two servers, although that usage is expected to be rare).

2. Protocol

The protocol defined in this document enables a client negotiate the time interval between whitespace keepalives, within a range determined by the server. Normally, the client starts the negotiation since not all kinds of the client support the feature.

The protocol defines a keepalive element and the normal negotaition process is quite simple, demonstrated as following:

  1. Server announces keepalive feature with a range of time intervals.
  2. Client starts the keepalive negotiation by specifying a time interval.
  3. Server checks the value and relpies with success or failure.

Then server and client send whitespace keepalive to each other at the agreed time interval.

3. Use Cases

3.1 Stream Feature

During the stream negotiation process, the server can advertise this feature. The feature is negotiated after the resource binding. (See Recommended Order of Stream Feature Negotiation (XEP-0170) [2] regarding the recommended order of stream feature negotiation.)

Example 1. Server lists feature in the stream negotiation stage
C: <stream:stream

C: <stream:stream
S:  <stream:features>
        <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
        <keepalive xmlns='urn:xmpp:keepalive:0'>
          <interval min='60' max='300'/>

3.2 Negotiate Keepalive

Client negotiates the keepalive feature by providing an interval value based on server limits and its own condition. The interval SHOULD be a positive interger, and zero is invalid.

Example 2. Client sends its negotiating keepalive time interval
<iq from='client@example.com/foo' id='p03ns61g' to='example.com' type='set'>
  <keepalive xmlns='urn:xmpp:keepalive:0'>

The server checks the keepalive interval value and returns a success:

Example 3. Server returns success of keepalive negotiation
<iq from='example.com' id='p03ns61g' to='client@example.com/foo' type='result'/>

If a problem occurs, the server returns an error (in this example, the client sent a value outside the range of the server's preferences):

Example 4. Server returns failure of keepalive negotiation
<iq from='example.com' id='p03ns61g' to='client@example.com/foo' type='error'>
  <error type='cancel'>
    <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>

Then both the server and the client send whitespace keepalives at the interval of the negotiated value. The server SHOULD check to see if has received keepalives and MAY drop the connection if it has not received a keepalive for a period of time significantly longer than the negotiated value (the client MAY also implement this behavior).

4. Implementation Notes

Several things need to be noted:

  1. Both parties SHOULD keep a record of the keepalive status and honor the negotiated value when allowing stream resumption and session recreation. See Stream Management (XEP-0198) [3]
  2. The length of the keepalive interval depends on the service type and network environment. Implementations are encouraged to use appropriate values based on implementation and deployment experience.

5. Security Considerations

During negotiation, the server MUST check the keepalive interval value and reject any invalid values.

6. IANA Considerations

This document requires no interaction with the Internet Assigned Numbers Authority (IANA) [4].

7. XMPP Registrar Considerations

7.1 Protocol Namespaces

The XMPP Registrar [5] is requested to issue an initial namespace 'urn:xmpp:keepalive:0'

7.2 Stream Features

The XMPP Registrar [5] is requested to issue an initial stream feature namespace 'urn:xmpp:keepalive:0'.

8. XML Schema

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

<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'

  <xsd:element name='keepalive'>
      <xsd:attribute name='min' type='positiveShort' use='optional'/>
      <xsd:attribute name='max' type='positiveShort' use='optional'/>
      <xsd:assert test='@min le @max'/>
      <xsd:element name='interval' type='positiveShort' minOccurs='0' maxOccurs='1'/>

  <xsd:simpleType name='positiveShort'>
    <xsd:restriction base='xsd:unsignedShort'>
      <xsd:minExclusive value='0'/>


9. Acknowledgements

Thanks to Matt Miller and Peter Saint-Andre for their feedback.


Appendix A: Document Information

XMPP Standards Foundation
Standards Track
Last Updated
Approving Body
XMPP Council
Superseded By
Short Name
Source Control

This document in other formats: XML  PDF

Appendix B: Author Information

Ming Ji


This XMPP Extension Protocol is copyright © 1999 – 2024 by the XMPP Standards Foundation (XSF).


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 <https://xmpp.org/about/xsf/ipr-policy> or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).

Visual Presentation

The HTML representation (you are looking at) is maintained by the XSF. It is based on the YAML CSS Framework, which is licensed under the terms of the CC-BY-SA 2.0 license.

Appendix D: Relation to XMPP

The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 6120) and XMPP IM (RFC 6121) 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 <https://xmpp.org/community/> 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-0170: Recommended Order of Stream Feature Negotiation <https://xmpp.org/extensions/xep-0170.html>.

3. XEP-0198: Stream Management <https://xmpp.org/extensions/xep-0198.html>.

4. 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/>.

5. 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 <https://xmpp.org/registrar/>.

Appendix H: Revision History

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

  1. Version 0.1 (2011-08-18)

    Initial published version.

  2. Version 0.0.1 (2011-07-19)

    First draft.


Appendix I: Bib(La)TeX Entry

  title = {Whitespace Keepalive Negotiation},
  author = {Ji, Ming},
  type = {XEP},
  number = {0304},
  version = {0.1},
  institution = {XMPP Standards Foundation},
  url = {https://xmpp.org/extensions/xep-0304.html},
  date = {2011-07-19/2011-08-18},