Click here to Skip to main content
13,048,766 members (88,068 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 9 Sep 2011

Jabber Client using MatriX XMPP Library

, 9 Sep 2011
Rate this:
Please Sign up or sign in to vote.
Jabber Client using Matrix XMPP Library
Jabber Client


In this article, I'm going to explain how to implement the XMLPP client using MatriX library. My client application would allow only point to point communication.

What is MatriX Library

MatriX is a library for the eXtensible Messaging and Presence Protocol (XMPP) for the Microsoft .NET platform. MatriX can be used to build high quality and high performance XMPP software products.

To get started with the Matrix XMPP library, you can download the SDK here.

What is XMPP

XMPP is a shortcut of Extensible Messaging and Presence Protocol, which is an open standard communication protocol for message-oriented middleware based XML. The XMPP is an open XML technology for real-time communication, which powers a wide range of applications including instant messaging, presence, media negotiation, whiteboarding, collaboration, lightweight middleware, content syndication, and generalized XML routing.

Every user on the XMLPP network has a unique Jabber ID (usually abbreviated as JID). The JID is structured like an e-mail address with a username and a domain name for the server where that user resides, separated by an at sign (@), such as

To get a better idea about Xmpp, check out Wiki XMPP.


To use the MatriX, you need to add Matrix.dll as a reference. For this application, we need to include the following namespaces:

using Matrix;
using Matrix.Xmpp; 
using Matrix.Xmpp.Client; 

Create a new XMLPP client instance:

XmppClient xmppClient = new XmppClient();

Set the XMPP Client Properties

xmppClient.Compression = false;
xmppClient.Hostname = null;
xmppClient.ResolveSrvRecords = true;
xmppClient.StartTls = true;
xmppClient.Status = "Online";
xmppClient.Show = Show.NONE;
Console.WriteLine("Enter your JID/UserId: (Ex:");
string jidId = Console.ReadLine();
Console.WriteLine("Enter your password: ");
string password = Console.ReadLine();

Jid jid = new Jid(jidId);
xmppClient.Password = password;
xmppClient.Username = jid.User;

Event Handlers

xmppClient.OnLogin += new EventHandler<matrix.eventargs>(XmppClient_OnLogin);
xmppClient.OnAuthError += 
	new EventHandler<matrix.xmpp.sasl.sasleventargs>(XmppClient_OnAuthError);
xmppClient.OnError += new EventHandler<matrix.exceptioneventargs>(XmppClient_OnError);
xmppClient.OnRosterEnd += new EventHandler<matrix.eventargs>(XmppClient_OnRosterEnd);

Open the connection and send the presence:

xmppClient.SendPresence(, "Online");

Get Online Users

xmppClient.OnPresence += new EventHandler<presenceeventargs>(XmppClient_OnPresence);
private static void XmppClient_OnPresence(object sender, PresenceEventArgs pres)
        Console.WriteLine("{0}@{1}  {2}", pres.Presence.From.User, 
			pres.Presence.From.Server, pres.Presence.Type);

Receive the Incoming Messages

xmppClient.MessageFilter.Add(new Jid(JID_Receiver), 
	new BareJidComparer(), 
	new EventHandler<messageeventargs>(XmppClient_OnMessage), null);

private static void XmppClient_OnMessage(object sender, MessageEventArgs e)
    if (e.Message.Body != null)
        Console.WriteLine("{0}: {1}", e.Message.From.User, e.Message.Body);

Send Messages to your Chat Partner

Console.WriteLine("Enter Chat Roster JID:");
string JID_Receiver = Console.ReadLine();
xmppClient.Send(new Message(new Jid(JID_Receiver),, sendMessage));

Finally, close the connection


What is BOSH

BOSH is standard for Bidirectional-streams Over Synchronous HTTP and it can be used to transport XMPP stanzas. The result is an HTTP binding (BOSH) for XMPP communications that is useful in situations where a device or client is unable to maintain a long-lived TCP connection to an XMPP server.

How to Use BOSH

If you are going to use bosh instead of socket, you need to set the transport type as BOSH.

xmppClient.Transport = Matrix.Net.Transport.BOSH;
xmppClient.Uri = new System.Uri("http://localhost:5280/http-bind");


Jabber Client

Jabber Client

Get the Latest Binary

Get the latest version of MatriX library from here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Singapore Singapore
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow can i create JID and configure Server and client for chat Pin
Kuldeep Sahu22-Oct-15 4:44
memberKuldeep Sahu22-Oct-15 4:44 
GeneralMy vote of 1 Pin
Miklo B19-Feb-15 12:36
memberMiklo B19-Feb-15 12:36 
Questionhow could i recognize that it is connected to server or not Pin
Member 112828523-Dec-14 3:08
memberMember 112828523-Dec-14 3:08 
QuestionBut Matrix is not a free library Pin
vaibhavtiwari26016-Sep-14 23:10
membervaibhavtiwari26016-Sep-14 23:10 
QuestionHow To send XML Request to XMPP server (Without matrix) Pin
ivasu5-Sep-14 19:14
memberivasu5-Sep-14 19:14 
QuestionServerless... Is it possible? Pin
Anastasios Mavrommatis11-Feb-14 3:07
memberAnastasios Mavrommatis11-Feb-14 3:07 
Questionnot able to connect to Pin
rabti ranjan30-Jul-12 5:44
memberrabti ranjan30-Jul-12 5:44 
QuestionJabber client with GTalk Pin
ballchris1313-Sep-11 5:55
memberballchris1313-Sep-11 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 9 Sep 2011
Article Copyright 2011 by K.Kirivarnan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid