xmpp Getting started with xmpp

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


The Extensible Messaging and Presence Protocol (XMPP) is a network protocol that uses XML to exchange structured data between two or more network connected entities in near-real-time. XMPP was created to satisfy the IETFs guidelines for instant messaging and presence protocols (RFC 2779), but its purpose goes far beyond IM. It is also used as a message-oriented middleware, for machine-to-machine (M2M) communication and for the Internet of Things (IoT).

The lightweight XMPP core protocol provides users with

  • strong authentication
  • global addresses
  • structured and extensible format for data exchange

The extensible approach makes it possible to build custom protocols on top of XMPP core.

The core XMPP protocol is defined in RFC 6120 and is managed by the Internet Engineering Task Force (XMPP). The instant messaging extensions are defined in RFC 6121, and a third document (RFC 7622) defines the format of XMPP addresses, also called "Jabber Identifiers" (JIDs). Additional functionality is specified in the form of XMPP Extension Protocols (XEPs), which are created by the community and maintained by the XMPP Standards Foundation (XSF).


VersionNotesRelease Date
1.0Core: RFC 6120, IM: RFC 6121, Address: RFC 76222011-03-01
0.9Core: RFC 3920, IM: RFC 3921, Address: RFC 61222004-10-01

Connecting and sending a message

SleekXMPP (Python)

import sleekxmpp

client = sleekxmpp.Client("address@example.net", "password")
client.send_message(mto="remote@example.net", mbody=self.msg)

Smack (Java / Android)

XMPPTCPConnection connection = new XMPPTCPConnection("user", "password", "example.org")
Message message = new Message("otheruser@example.net", "Hi, how are you?");

Create Xmpp Client Connection Using agsxmpp library

public void OpenXmppConnection(int port, bool useSsl, string serverJid, string userName, string password)
                _xmppClientConnection.AutoResolveConnectServer = true;
                _xmppClientConnection.Port = port;
                _xmppClientConnection.UseSSL = useSsl;
                _xmppClientConnection.Server = serverJid;
                _xmppClientConnection.Username = userName;
                _xmppClientConnection.Password = password;
                _xmppClientConnection.Resource = "web";

                //authenticate and open connection with server
            catch (Exception ex)

Creating a Chat Session and sending a message

Smack (Java)

  • Using Smack 4.1
  • It is recommended to include Smack as Maven dependency in your project (e.g. by using gradle or Maven).
  • Otherwhise the following Smack artifacts/jars have to be added manually to the classpath: smack-core, smack-extensions, smack-experimental, smack-im, smnack-tcp, smack-java7
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

public void sendMessage() {

XMPPTCPConnectionConfiguration config = 

XMPPTCPConnection connection = new XMPPTCPConnection(config);

connection.login("test1", "test1pwd"); 

ChatManager chatManager = ChatManager.getInstanceFor(connection);
String test2JID = "test2@domain.example";
Chat chat = chatManager.createChat(test2JID);
chat.sendMessage("Hello, how are you?");


Send a message using agsxmpp library

        public class ConversationManager
            #region ClassMemeber
            private XmppClientConnection _xmppClientConnection = null;
     public ConversationManager(XmppClientConnection con)
                _xmppClientConnection = con;

 public void SendMessage(string message, string to, string guid, string type)
                if (_xmppClientConnection != null)
                    Jid jidTo = new Jid(to);
                    agsXMPP.protocol.client.Message mesg = new agsXMPP.protocol.client.Message(jidTo, _ConnectionWrapper.MyJid,

                    mesg.Id = guid;
                    mesg.AddChild(new agsXMPP.protocol.extensions.msgreceipts.Request());//request delievery
            catch (Exception ex)


Got any xmpp Question?