Extensible Messaging and Presence Protocol (XMPP)
The Extensible Messaging and Presence Protocol (XMPP) is a protocol for streaming XML elements in order to exchange messages and presence information.
The XMPP Core uses main features like
- XML Streams
- <message/>, <presence/>, and <iq/> children of the stream root
The basic functionality expected of XMPP is instant messaging (IM) and presence application.
Important requirement are
- Exchange messages with other users
- Exchange presence information with other users
- Manage subscriptions to and from other users
- Manage items in a contact list (in XMPP this is called a "roster")
- Block communications to or from specific other users
There are many providers who had built in libraries as mentioned in XMPP Standard foundation check link http://xmpp.org/xmpp-software/libraries/ .
The example below described is based on the agsXMPP SDK developed in managed C# dedicated to .NET and Mono technologies. Since, it is dual licensed (GPL) free DLL developed by and they also provide support for issues.
Before moving onto example there is important requirement to implement chat i.e., Chat server installation. I am using Openfire server to fulfill the requirement. For installation follow the link http://www.igniterealtime.org/projects/openfire/documentation.jsp
Important particulars for this implementation is
- JID – Jabber Id, a unique id in the openfire server for each user.
- Roster- User’s contact is roster.
How to login to the server?
Add the following code after successful login from your application.
AgsXMPP.XmppClientConnection objXmpp = new agsXMPP.XmppClientConnection();
Jid jid = new Jid ("xyz@server name"); //ex: firstname.lastname@example.org – gmail.com is server for google.mail
objXmpp.Server = jid.Server;
objXmpp.Username = jid.User;
objXmpp.Password = ******; //your password of account.
objXmpp.AutoResolveConnectServer = true;
objXmpp.OnLogin += loggedIn; // loggedIn is handler for successful login to server.
objXmpp.OnAuthError += loginFailed;
Catch (exception ex)
The loggedin handler is shown below
Private void loggedIn (object o)
//lblStatus.Text = "Logged in and Active.";
The login failed handler is shown below
Private void loginFailed (object o, agsXMPP.Xml.Dom.Element el)
//lblStatus.Text = "Invalid credentials.”
When the loggedin handler executes it assures you that user credentials are valid and logged in.
Part 1 we discussed only on the Login part using AgsXmpp.dll.
In next part i.e., Part 2 we shall discuss upon Recieving roster list of the user using AgsXmpp.