O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Practical XMPP

Book Description

Unleash the power of XMPP in order to build exciting, real-time, federated applications based on open standards in a secure and highly scalable fashion

About This Book

  • Learn about the fundamentals of XMPP and be able to work with the core functionality both server-side and in the browser
  • Build a simple 1-to-1 chat (the “Hello World” of XMPP), explore multi-user chat, publish subscribe systems, and work with a decentralized social network
  • Author Lloyd Watkins is a member of the XMPP standards committee

Who This Book Is For

If you want to learn about the fundamentals of XMPP, be able to work with the core functionality both server-side and in the browser then this book is for you.No knowledge of XMPP is required, or of TCP/IP networking. It's important that you already know how to build applications of some form, and are looking get a better understanding of how to implement XMPP for one or more of its many uses. You should be interested in the decentralized web, know HTML, and likely know JavaScript and NodeJS. You will probably know JSON, and hopefully XML (this is the native output of XMPP).

What You Will Learn

  • Install and configure an XMPP server and use it to connect from a traditional desktop client and send a message
  • Build a simple server-side application that will respond to messages from our logged in desktop client
  • Install and run XMPP-FTW, connect to the server from the browser, and handle incoming/outgoing messages
  • Connect to a multi-user chat room, send/receive stanzas, add a room password, join a protected room, set the room’s subject, and change a user's affiliation
  • Get to grips with the publish-subscribe extension of XMPP and use it to build a pusher system that can make any website real-time
  • Build a simple XMPP component and create an extension for XMPP-FTW that allows you to use your own custom format
  • Build an XMPP version of the classic game “Pong”

In Detail

XMPP (eXtensible Messaging and Presence Protocol) is a messaging protocol that enables communication between two or more devices via the Internet.

With this book, developers will learn about the fundamentals of XMPP, be able to work with the core functionality both server-side and in the browser, as well as starting to explore several of the protocol extensions. You will not only have a solid grasp of XMPP and how it works, but will also be able to use the protocol to build real-world applications that utilize the power of XMPP. By the end of this book, you will know more about networking applications in general, and have a good understanding of how to extend XMPP, as well as using it in sample applications.

Style and approach

Through a number of hands-on projects, this book shows you how to build usable applications that highlights a feature of XMPP.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Practical XMPP
    1. Practical XMPP
    2. Credits
    3. About the Authors
    4. About the Reviewers
    5. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    7. 1. An Introduction to XMPP and Installing Our First Server
      1. What is XMPP?
        1. Uses of XMPP
        2. XMPP and the Web
        3. Installing Node.js and library dependencies
      2. Installing our XMPP server
        1. Installing the server
        2. Configuring the server
        3. Testing our setup
        4. Creating a test account
        5. Installing an XMPP client
      3. Summary
    8. 2. Diving into the Core XMPP Concepts
      1. Introducing the Jabber ID
        1. Message routing
      2. Basic building blocks of XMPP communication
      3. <presence/>
        1. Presence subscriptions
        2. Directed Presence
        3. Client capabilities
      4. Presence overloading
      5. <message/>
        1. Delivery receipts
        2. XHTML-IM
      6. Chat state notifications
      7. <iq/>
      8. Summary
    9. 3. Building a One-on-One Chat Bot - The "Hello World" of XMPP
      1. C2S connection life cycle
      2. Authenticating with a server
      3. Installing node-xmpp-client
      4. Building our echo bot
        1. Creating a new user
        2. Connecting to the server
      5. Telling the server we're online
        1. Listening for incoming stanzas
        2. Reading the chat stanza with ltx
      6. Responding to incoming messages
      7. Extending our echo bot
        1. Responding to presence subscription requests
        2. Returning results from DuckDuckGo Instant Answers API
        3. Sending chat state notifications
      8. Signing off
      9. Summary
    10. 4. Talking XMPP in the Browser Using XMPP-FTW
      1. Interacting with XMPP in the browser
      2. BOSH
      3. The WebSocket protocol
      4. Introducing XMPP-FTW
        1. Installing XMPP-FTW
        2. Playing with XMPP-FTW using the demo application
      5. Talking to our bot from the browser
        1. Building a WebSocket-enabled web server in Node.js
        2. Talking WebSockets from a browser
        3. Installing XMPP-FTW and getting messaging!
      6. Chatting with our XMPP bot
      7. Login
        1. Interacting with the chat bot
      8. Seeing what the chat bot is up to...
      9. Hello (hello, hello...)! Is there anybody out there?
      10. Summary
    11. 5. Building a Multi-User Chat Application
      1. The basics of MUC
      2. Joining a room
        1. Your role and identity within a room
        2. Sending and receiving messages
      3. Discovering MUC
      4. Configuring our chat room using data forms
        1. The basics of the data form
        2. Getting our MUC room configuration
        3. Updating the room configuration
      5. Data forms in XMPP-FTW
      6. Creating a chat room
        1. Managing the users
        2. Configuration updates
        3. Leaving a room
        4. Destroying the room
      7. Building with XMPPMUC
      8. Updating Prosody to provide an MUC service
        1. Connecting with our XMPP client
      9. Extending our chat bot to work with an MUC
      10. Writing a browser-based MUC client
        1. Setting things up server-side
      11. Building the client
        1. Connecting anonymously
        2. Listing the available chat rooms
        3. Where the action happens
        4. Displaying the chat room HTML and handling users
      12. Handling incoming messages
        1. Sending a message
        2. Wrapping up
      13. Summary
    12. 6. Make Your Static Website Real-Time
      1. Are we there yet?
      2. Interacting with Publish-Subscribe
      3. Discovery
      4. Subscribing
      5. Subscriptions, affiliations, and access models
        1. Creating and configuring nodes
        2. Retrieving items
        3. Publishing items
      6. Making your website real-time
        1. Configuring Prosody
        2. Building a server-side publishing mechanism
        3. Building our real-time client
      7. Setting up the server
      8. Lining up our static website
      9. Let's get real-time...
        1. Subscribing to a node
        2. Retrieving historical results
      10. Getting real-time
      11. Taking things further
      12. Summary
    13. 7. Creating an XMPP Component
      1. Connection flow for components
      2. Configuring a component in Prosody
      3. Building our first XMPP component
        1. Creating a component and connecting it to the server
        2. Receiving a stanza and responding to a DISCO#info query
      4. Responding to a chat message
        1. Creating a client that connects to the component
        2. Running your new component and client
      5. Summary
    14. 8. Building a Basic XMPP-Based Pong Game
      1. Overview of Basic XMPP Pong
      2. Getting Started
      3. Developing the HTML canvas
        1. Adding the mouse listeners for moving the paddle
      4. Drawing and updating the game
      5. Sending and receiving XMPP messages in Pong
      6. Sending and receiving a Hello message
        1. Sending a paddle update
        2. Receiving a paddle update
      7. Connecting the clients
      8. Advertising the Pong feature of clients (Client DISCO)
      9. Issues with a basic implementation
      10. Summary
    15. 9. Enhancing XMPPong with a Server Component and Custom Messages
      1. Designing the information flow for XMPPong
      2. Developing the XMPP component for XMPPong
        1. Setting up a game loop in the component
        2. Starting and updating the game
      3. Maintaining the ball state in the component
        1. Bounces and misses
        2. Expecting paddle updates
        3. Implementing messages from the component to the clients
        4. Handling incoming messages from the clients
      4. Handing DISCO#info requests
        1. Creating an XMPP-FTW extension to read messages within our namespace
      5. Developing the client
        1. Starting the XMPP-FTW server
        2. Checking in to the component and receiving dimensions
        3. Drawing code in the client
      6. Modifying the browser view
      7. Running the server and clients
      8. Summary
    16. 10. Real-World Deployment and XMPP Extensions
      1. Server Modules
      2. DNS setup and SRV records
      3. Server-to-server communications
      4. XMPP security
      5. XMPP scalability
      6. User Registration
      7. About the XMPP Standards Foundation
      8. XMPP and the new rise of multi-user chat
      9. XMPP and the Internet of Things
      10. XMPP and Universal Plug-n-Play
      11. XMPP and WebRTC
      12. The Future of XMPP
      13. Summary