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
The basic functionality expected of XMPP is instant messaging (IM) and for user presence in 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
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
ag-software.net and they also provide support for issues.
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: xyz@abc.com – abc is the server
objXmpp.Server = jid.Server;
objXmpp.Username = jid.User;
objXmpp.Password = ******; //your password of account.
objXmpp.AutoResolveConnectServer = true;
Try
{
objXmpp.OnLogin += loggedIn; // loggedIn is handler for successful login to server.
objXmpp.OnAuthError += loginFailed;
objXmpp.Open ();
}
Catch (exception ex)
{
}
The loggedin handler is shown below
Private void loggedIn (object o)
{
//Logged in and Active
}
The login failed handler is shown below
Private void loginFailed (object o, agsXMPP.Xml.Dom.Element el)
{
//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 .
In next part i.e.,
Part 2 we shall discuss upon
Recieving roster list of the user using AgsXmpp.