Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Practical XMPP
Practical XMPP
Practical XMPP
Ebook465 pages3 hours

Practical XMPP

Rating: 0 out of 5 stars

()

Read preview

About this ebook

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).

LanguageEnglish
Release dateSep 30, 2016
ISBN9781785282096
Practical XMPP

Related to Practical XMPP

Related ebooks

Internet & Web For You

View More

Related articles

Reviews for Practical XMPP

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Practical XMPP - Lloyd Watkin

    Table of Contents

    Practical XMPP

    Credits

    About the Authors

    About the Reviewers

    www.PacktPub.com

    eBooks, discount offers, and more

    Why subscribe?

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. An Introduction to XMPP and Installing Our First Server

    What is XMPP?

    Uses of XMPP

    XMPP and the Web

    Installing Node.js and library dependencies

    Installing our XMPP server

    Installing the server

    Configuring the server

    Testing our setup

    Creating a test account

    Installing an XMPP client

    Summary

    2. Diving into the Core XMPP Concepts

    Introducing the Jabber ID

    Message routing

    Basic building blocks of XMPP communication

    Presence subscriptions

    Directed Presence

    Client capabilities

    Presence overloading

    Delivery receipts

    XHTML-IM

    Chat state notifications

    Summary

    3. Building a One-on-One Chat Bot - The Hello World of XMPP

    C2S connection life cycle

    Authenticating with a server

    Installing node-xmpp-client

    Building our echo bot

    Creating a new user

    Connecting to the server

    Telling the server we're online

    Listening for incoming stanzas

    Reading the chat stanza with ltx

    Responding to incoming messages

    Extending our echo bot

    Responding to presence subscription requests

    Returning results from DuckDuckGo Instant Answers API

    Sending chat state notifications

    Signing off

    Summary

    4. Talking XMPP in the Browser Using XMPP-FTW

    Interacting with XMPP in the browser

    BOSH

    The WebSocket protocol

    Introducing XMPP-FTW

    Installing XMPP-FTW

    Playing with XMPP-FTW using the demo application

    Talking to our bot from the browser

    Building a WebSocket-enabled web server in Node.js

    Talking WebSockets from a browser

    Installing XMPP-FTW and getting messaging!

    Chatting with our XMPP bot

    Login

    Interacting with the chat bot

    Seeing what the chat bot is up to...

    Hello (hello, hello...)! Is there anybody out there?

    Summary

    5. Building a Multi-User Chat Application

    The basics of MUC

    Joining a room

    Your role and identity within a room

    Sending and receiving messages

    Discovering MUC

    Configuring our chat room using data forms

    The basics of the data form

    Getting our MUC room configuration

    Updating the room configuration

    Data forms in XMPP-FTW

    Creating a chat room

    Managing the users

    Configuration updates

    Leaving a room

    Destroying the room

    Building with XMPPMUC

    Updating Prosody to provide an MUC service

    Connecting with our XMPP client

    Extending our chat bot to work with an MUC

    Writing a browser-based MUC client

    Setting things up server-side

    Building the client

    Connecting anonymously

    Listing the available chat rooms

    Where the action happens

    Displaying the chat room HTML and handling users

    Handling incoming messages

    Sending a message

    Wrapping up

    Summary

    6. Make Your Static Website Real-Time

    Are we there yet?

    Interacting with Publish-Subscribe

    Discovery

    Subscribing

    Subscriptions, affiliations, and access models

    Creating and configuring nodes

    Retrieving items

    Publishing items

    Making your website real-time

    Configuring Prosody

    Building a server-side publishing mechanism

    Building our real-time client

    Setting up the server

    Lining up our static website

    Let's get real-time...

    Subscribing to a node

    Retrieving historical results

    Getting real-time

    Taking things further

    Summary

    7. Creating an XMPP Component

    Connection flow for components

    Configuring a component in Prosody

    Building our first XMPP component

    Creating a component and connecting it to the server

    Receiving a stanza and responding to a DISCO#info query

    Responding to a chat message

    Creating a client that connects to the component

    Running your new component and client

    Summary

    8. Building a Basic XMPP-Based Pong Game

    Overview of Basic XMPP Pong

    Getting Started

    Developing the HTML canvas

    Adding the mouse listeners for moving the paddle

    Drawing and updating the game

    Sending and receiving XMPP messages in Pong

    Sending and receiving a Hello message

    Sending a paddle update

    Receiving a paddle update

    Connecting the clients

    Advertising the Pong feature of clients (Client DISCO)

    Issues with a basic implementation

    Summary

    9. Enhancing XMPPong with a Server Component and Custom Messages

    Designing the information flow for XMPPong

    Developing the XMPP component for XMPPong

    Setting up a game loop in the component

    Starting and updating the game

    Maintaining the ball state in the component

    Bounces and misses

    Expecting paddle updates

    Implementing messages from the component to the clients

    Handling incoming messages from the clients

    Handing DISCO#info requests

    Creating an XMPP-FTW extension to read messages within our namespace

    Developing the client

    Starting the XMPP-FTW server

    Checking in to the component and receiving dimensions

    Drawing code in the client

    Modifying the browser view

    Running the server and clients

    Summary

    10. Real-World Deployment and XMPP Extensions

    Server Modules

    DNS setup and SRV records

    Server-to-server communications

    XMPP security

    XMPP scalability

    User Registration

    About the XMPP Standards Foundation

    XMPP and the new rise of multi-user chat

    XMPP and the Internet of Things

    XMPP and Universal Plug-n-Play

    XMPP and WebRTC

    The Future of XMPP

    Summary

    Practical XMPP


    Practical XMPP

    Copyright © 2016 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: September 2016

    Production reference: 1280916

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham 

    B3 2PB, UK.

    ISBN 978-1-78528-798-5

    www.packtpub.com

    Credits

    About the Authors

    Lloyd Watkin has over 10 years of experience in building for the Web. A great believer in open source and open standards, he has contributed to, started, and led many successful open source projects and is also an international conference speaker.

    Lloyd was knowingly introduced to XMPP in 2012 and hasn't looked back. Its open standard base and the ability to code clients, servers, components in any language leads to a very diverse and healthy environment. Its relevance only seems to increase as new technologies (not imagined at the time of creation) come into existence.

    I would like to thank my family and friends for their support and damaged ear drums. I would also like to thank the XSF and the XMPP community as a whole for being supportive, welcoming, and always striving to improve and extend the XMPP ecosystem.

    David Koelle is a principal software engineer at Charles River Analytics Inc. in Cambridge, Massachusetts, USA, where he has employed XMPP on projects to facilitate collaboration and shared situational awareness among distant teams. He is also the author of JFugue, a popular open source music programming API for Java and other JVM languages, and he is a co-organizer for the Boston Android Meetup.

    David has delivered several award-winning talks at high-profile conferences including JavaOne and SXSW. In addition to his technical work in software engineering and systems engineering, he finds opportunities to mentor engineers to help them grow in their careers and recognize the value that proactive leadership can bring to engineers and their environments. David is a graduate of Worcester Polytechnic Institute (WPI).

    About the Reviewers

    Emilien Kenler, after working on small web projects, began focusing on game development in 2008 while he was in high school. Until 2011, he worked for different groups and specialized in system administration.

    In 2011, he founded a company that sold Minecraft servers while studying Computer Science Engineering. He created a lightweight IaaS (https://github.com/HostYourCreeper/) based on new technologies such as Node.js and RabbitMQ.

    Thereafter, he worked at TaDaweb as a system administrator, building its infrastructure and creating tools to manage deployments and monitoring.

    In 2014, he began a new adventure at Wizcorp, Tokyo. The same year, Emilien graduated from the University of Technology of Compiègne, France.

    Since 2016, he’s a systems engineer at Vesper, the company behind TableSolution, a leading restaurant reservation and CRM system.

    Emilien has written MariaDB Essentials, Packt Publishing. He has also contributed as a reviewer on Learning Nagios 4, MariaDB High Performance, OpenVZ Essentials, Vagrant Virtual Development Environment Cookbook, Getting Started with MariaDB Second Edition and Mastering Redis, all by Packt Publishing.

    Ian Wild's career has always focused primarily on communication and learning. Ian, a physicist by profession, spent 15 years in private industry designing communication systems software (Lucent Technologies, Avaya) before specializing in the development and deployment of learning management systems. Ian has a particular interest in the integration of legacy systems. He is currently the lead developer for Skills for Health, the sector skills council for the UK's health sector. He is responsible for one of the country's busiest online learning platforms (the National Skills Academy for Health).

    www.PacktPub.com

    eBooks, discount offers, and more

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Preface

    XMPP has been around since 1999, and in that time has been rediscovered several times over by generation after generation of programmers. Originally started to unify what was a massively fragmented instant messaging scene, XMPP has continued to show its relevance as new technologies and technology uses emerge.

    We'll be making use of the Prosody XMPP server, a fast, resource light system written in LUA, as well as Node.js to write our own projects. The two main libraries we'll be using to interact with XMPP are node-xmpp on the server side and XMPP-FTW, a translation layer between XMPP’s XML messages and JSON, which is massively popular for use in the browser.

    Through this book, you'll learn about the core concepts of XMPP, build basic clients that will allow you to interact with the XMPP ecosystem at large, build time-saving bots, and even build an entire custom application using XMPP standards and your own extensions.

    The skills you'll learn in this book will allow you to create the next massively popular chat application built on the core standards, through to your own full-fledged Internet of Things (IoT) device that will collect, share, and respond to data from interconnected servers all over the world!

    What this book covers

    Chapter 1, An Introduction to XMPP and Installing Our First Server. Provides a brief introduction to the history of XMPP and its uses as well as installing and interacting with our first XMPP server.

    Chapter 2, Diving into the Core XMPP Concepts, reveals that XMPP covers a vast number of areas but at its core is very simple and extensible. Here we learn about the core concepts so when we come to building our XMPP applications later we understand what's going on.

    Chapter 3, Building a One-on-One Chat Bot - The Hello World of XMPP, show us how to build a simple chat bot and interact with it via a standard client.

    Chapter 4, Talking XMPP in the Browser Using XMPP-FTW, we introduce XMPP-FTW and shows us how to build some basic functionality.

    Chapter 5, Building a Multi-User Chat Application, how to  create a very basic multi user chat client in the browser and begin chatting with our XMPP users.

    Chapter 6, Make Your Static Website Real-Time, takes a standard static website and add real time data to it pushed via XMPP, making even the dullest website dynamic and exciting!  

    Chapter 7, Creating an XMPP Component, shows how to create our first server-side component, which let you develop business logic without modifying the server itself.

    Chapter 8, Building a Basic XMPP-Based Pong Game, how to create a simple application, using standard chat messages to convey game state. We also learn about Client DISCO for discovering capabilities of a client connected to a chat server.

    Chapter 9, Enhancing XMPPong with a Server Component and Custom Messages, explains how to develop a full-fledged XMPP demonstration application, including a server-side component, an XMPP-FTW extension that allows us to create our own messages, and clients that talk to the server using those messages.

    Chapter 10, Real-World Deployment and XMPP Extensions, presents considerations for deploying your app, including security and scalability. These capabilities are described in XMPP Extension Protocols (XEPs), and in this chapter we also take the opportunity to introduce several additional XEPs that describe emerging XMPP features, including Internet of Things and WebRTC.

    What you need for this book

    The requirements for all sections of this book after fairly minimal. Any computer built within the past five years that supports a recent version of Linux, Mac, or Windows will be sufficient. An up-to-date browser will be required for websocket support, but even then the project is able to fall back to standard HTTP. You machine should have at least 128 Mb of free RAM and the same amount of hard drive space.

    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 know JavaScript and NodeJS. You will probably know JSON, and hopefully XML (this is the native output of XMPP).

    Conventions

    In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

    Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: First we'll install libicu and libexpat-dev.

    A block of code is set as follows:

    modules_enabled = {

            roster;

            saslauth;

            tls;

            dialback;

            disco;

            version;

            uptime;

            time;

            ping,

            register;

            posix;

            bosh;

    };

    Any command-line input or output is written as follows:

    $ curl https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash $ source ~/.bashrc $ nvm install 6 $ node -v

    New terms and Important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: The shortcuts in this book are based on the Mac OS X 10.5+ scheme.

    Note

    Warnings or important notes appear in a box like this.

    Tip

    Tips and tricks appear like this.

    Reader feedback

    Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail feedback@packtpub.com, and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

    Customer support

    Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

    Downloading the example code

    You can download the example code files for this book 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 files e-mailed directly to you.

    You can download the code files by following these steps:

    Log in or register to our website using your e-mail address and password.

    Hover the mouse pointer on the SUPPORT tab at the top.

    Click on Code Downloads & Errata.

    Enter the name of the book in the Search box.

    Select the book for which you're looking to download the code files.

    Choose from the drop-down menu where you purchased this book from.

    Click on Code Download.

    Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

    WinRAR / 7-Zip for Windows

    Zipeg / iZip / UnRarX for Mac

    7-Zip / PeaZip for Linux

    The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Practical-XMPP. We also have other code bundles

    Enjoying the preview?
    Page 1 of 1