-
Part I TE ⊲⊲ Chapter 1: Getting to Know XMPP RI AL XMPP Protocol and Architecture CO PY RI GH TE D MA ⊲⊲ Chapter 2: Designing XMPP Applications
-
-
1 Getting to Know XMPP What’s in This Chapter? ➤➤ The history of XMPP ➤➤ XMPP networks and connections ➤➤ XMPP’s three building block stanzas The eXtensible Messaging and Presence Protocol (XMPP) is, at its most basic level, a protocol for moving small, structured pieces of data between two places. From this humble basis, it has been used to build large-scale instant messaging systems, Internet gaming platforms, search engines, collaboration spaces, and voice and video conferencing systems.
-
❘ Chapter 1 Getting to Know XMPP What Is XMPP? XMPP, like all protocols, defines a format for moving data between two or more communicating entities. In XMPP’s case, the entities are normally a client and a server, although it also allows for peer-to-peer communication between two servers or two clients. Many XMPP servers exist on the Internet, accessible to all, and form a federated network of interconnected systems.
-
A Brief History of XMPP ❘5 The focus on small, structured bits of data gives the XMPP protocol extremely low latency and makes it extremely useful for real-time applications. These applications, which include collaborative spaces, games, and synchronization, are driving XMPP’s growth in popularity as developers experiment with the real-time Web. You will see how easy it is to make real-time web applications through this book’s examples.
-
❘ Chapter 1 Getting to Know XMPP Eventually the JSF and the extensions followed the naming change from Jabber to XMPP and became the XMPP Standards Foundation (XSF) and XMPP Extension Proposals (XEPs). By 2005, large-scale deployments of XMPP technology were well underway, highlighted by the launch of Google Talk, Google’s own XMPP-based IM service. Today, the XMPP ecosystem is quite large.
-
The XMPP Network Clients The majority of XMPP entities are clients, which connect to XMPP servers via the client-to-server protocol. Many of these entities are human-driven, traditional IM users, but there are also automated services running as bots. Clients must authenticate to an XMPP server somewhere. The server routes all stanzas the client sends to the appropriate destination.
-
❘ Chapter 1 Getting to Know XMPP Plug-ins Many XMPP servers can also be extended via plug-ins. These plug-ins are usually written in the same programming language as the server itself and run inside the server’s processes. Their purpose overlaps to a large degree with external components, but plug-ins may also access internal server data structures and change core server behavior.
-
XMPP Stanzas ❘9 Bare JIDs for clients are somewhat special, because the server itself will handle stanzas addressed to a client’s bare JID. For example, a message sent to a client’s bare JID will be forwarded to one or more connected resources of the user, or if the user is offline, stored for later delivery. Stanzas sent to full JIDs, however, are usually routed directly to the client’s connection for that resource.
-
❘ Chapter 1 Getting to Know XMPP Common Attributes All three stanzas support a set of common attributes. Whether they are attributes of , , or elements, the following attributes all mean the same thing. from Stanzas almost always have a from attribute. This attribute identifies the JID of the stanza’s origin.
-
XMPP Stanzas ❘ 11 data. In all these cases, the client uses the id attribute of the reply stanza to identify which request stanza it is associated with. In cases where many stanzas of the same type are sent in a short time frame, this capability is essential because the replies may be delivered out of order. Presence Stanzas The stanza controls and reports the availability of an entity. This availability can range from simple online and offline to the more complex away and do not disturb.
-
❘ Chapter 1 Getting to Know XMPP The first two stanzas set a user’s presence status to online or offline, respectively. These are also typically the first and last presence stanzas sent during an XMPP session. The next two examples both show extra presence information in the form of , , and children. The element is used to communicate the nature of the user’s availability.
-
XMPP Stanzas ❘ 13 Presence subscription stanzas can be identified by a type attribute that has a value of subscribe, unsubscribe, subscribed, or unsubscribed. The first two values request that a new presence subscription be established or an existing subscription be removed, and the other two are the answers to such requests. The following example shows Elizabeth and Mr. Darcy establishing a mutual presence subscription:
-
❘ Chapter 1 Getting to Know XMPP A stanza is fire and forget; there is no built in reliability, similar to e‑mail messages. Once the message has been sent, the sender has no information on whether it was delivered or when it was received. In some cases, such as when sending to a non-existent server, the sender may receive an error stanza alerting them to the problem.
-
XMPP Stanzas ❘ 15 The last stanza type is headline. These types of messages are used mostly by automated services that do not expect or support replies. If automatically generated e‑mail had a type attribute, it would use a value of headline. Message Contents Though stanzas are allowed to contain arbitrary extension elements, the and elements are the normal mechanisms provided for adding content to messages. Both of these child elements are optional.
-
❘ Chapter 1 Getting to Know XMPP type=’error’ id=’roster1’> Jane sent a malformed roster retrieval request to her server. The server replied with an error. Error stanzas are covered in detail later.
-
XMPP Stanzas ❘ 17 Error Stanzas All three of the XMPP stanzas have an error type, and the contents of each type of error stanza are arranged in the same pattern. Error stanzas have a well-defined structure, often including the contents of the original, offending stanza, the generic error information, and, optionally, an application-specific error condition and information. All error stanzas must have a type attribute set to error and one child element.
-
❘ Chapter 1 Getting to Know XMPP The following example IQ-error stanza shows a fully constructed error response to a publish-subscribe related stanza:
-
The Connection Life Cycle ❘ 19 Stream Set Up Once a connection is established to a given XMPP server, an XMPP stream is started. An XMPP stream is opened by sending the opening element to the server. The server responds by sending the response stream’s opening tag. Once XMPP streams are open in both directions, elements can be sent back and forth. At this stage of the connection life cycle, these elements will be related to the stream and the stream’s features.
-
❘ Chapter 1 Getting to Know XMPP Authentication XMPP allows for Transport Layer Security (TLS) encryption, and most clients use this by default. Once TLS support is advertised by the server, the client starts the TLS connection and upgrades the current socket to an encrypted one without disconnecting. Once TLS encryption is established, a new pair of XMPP streams is created.
-
Summary ❘ 21 You should now understand: ➤➤ XMPP is an open, standardized protocol, originally developed to replace proprietary IM networks. ➤➤ The XMPP protocol is more than a decade old and quite mature. ➤➤ XMPP is great for writing IM applications, but it also excels at any task that benefits from exchanging structured messages. ➤➤ Servers, clients, components, and plug-ins are all parts of XMPP networks and have their special uses.
-