

The XMPP client could be running on any of several types of computing devices, ranging from mobile phones and embedded devices to laptops and full-fledged desktops.
PIDGIN XMPP TUTORIAL CODE
Since the python-xmpp library handles the nitty-gritty of building, sending, and receiving the XML streams, you don’t need to memorise the XML samples - just look at them as illustrations, and not as code that you have to write yourself. Note: The XML streams shown below as examples are not as they would actually be in a live XMPP session, since I have omitted attributes of some elements, and omitted portions of the XML stream that are not required to illustrate the concept.



We need to understand the types of communication and interaction involved, however, so let’s begin. In this article, we’ll be using Python to write our code, and the python-xmpp library provides us a neat API. To write an XMPP client, we don’t need a thorough understanding of the XML streams that are exchanged between client and server, since we use libraries that abstract away the complexities of the underlying protocol, and provide an API to us. Presence is explained below.Īs already noted, the communication between client and server is in the form of XML streams, over the connection created at the beginning of the interaction.īefore we get down to the code, we need to define some terms and underlying concepts that are involved with the use of the XMPP protocol. This is a collection of presence data from different buddies of the user, which the client authenticated to the server. When authentication is successful, the client receives a response containing presence notification data.The server validates the received credentials against its user database and sends a response to the client.The client connects to the server and sends credentials like the username and password.The sequence of the initial interaction between client and server is as follows: Since our purpose in this article is to code our own Google Talk client, the hostname of the server we will use is, and the port we will use is 5222, the default port for the XMPP service. An explanation of networking, TCP/IP, IP addresses, ports and sockets is too much information to put into this article, so if these concepts are new to you, you could visit this Wikipedia article for some quick reading. We connect to the server using a TCP socket in our program. Since our primary focus is on clients, we won’t dig any more into the server part - we will just consider the server to be a “black box” entity available at a specific IP address/hostname and port number, which meaningfully responds to our XMPP requests. XMPP is used in a de-centralised client-server architecture, in which a server acts as an intermediary for the message transfer, and also manages services like the user account registration, authentication, buddy list database, etc. It uses XML streams to implement the entire message communication system. XMPP is an XML-based open standards protocol. Once you understand it, you can easily write your own XMPP/GTalk clients from the ground up, using the friendly and powerful Python scripting language. Exploring XMPP (formerly known as the Jabber protocol) is fun - it is a transparent and simple architecture. The popular Google Talk, which uses XMPP (Extensible Messaging and Presence Protocol), made this Instant Messaging protocol prominent among open standards protocols. Instant communication is the essence of social networking and the Internet.
