Using XMPP and Openfire server in ASP.NET C# - Part -2 - Blogs

Using XMPP and Openfire server in ASP.NET C# - Part -2

Roster in XMPP

Roster are the contacts of  user (contact list).


Roster Handlers in AgsXmpp

Let us discuss, the handlers other than the mentioned in part -1 i.e., (loggedin, loginfailed) are mentioned below

·         OnRosterItem

·         OnRosterEnd

·         OnRosterStart


Let us recap part -1 ( ) login part (we need here that code snippet for initializing the above mentioned handlers)


AgsXMPP.XmppClientConnection objXmpp = new agsXMPP.XmppClientConnection ();

Jid jid = new Jid ("xyz@server name"); //ex: –abc is server name

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;

objXmpp. OnRosterStart+= new ObjectHandler(objXmpp_OnRosterStart);

objXmpp.OnRosterItem+=new AgsXMPP.XmppClientConnection.RosterHandler(objXmpp_OnRosterItem);

objXmpp. OnRosterEnd+= new ObjectHandler(objXmpp _OnRosterEnd);

objXmpp.Open ();


Catch (exception ex)

{ }


OnRosterStart handler is shown below

 private  void objXmpp_OnRosterStart(object sender)



Onrosterstart handler is executed after the login is successful,  implies initiate any method or variable (ex. DataTable or Generic list to store the contacts ) to handle the Roster List item which is next event.


The OnRosterItem handler is shown below

private void objXmpp_OnRosterItem(object sender, RosterItem rosterItem)



    // rosterItem.Subscription


In the above mentioned handler, we can read every roster information (contact list) after successful OnRosterStart .


We can get below mentioned properties from RosterItem

·         Subscription (SubscriptionType enum )

·         JId


SubscriptionType is an enum with values

·         None – (not yet subscribed)

·         To – (sender subscribed waiting for your approval)

·         From – (receiver not accepted your subscription)

·         Both – (Both receiver and sender accepted the request)

In this event, you can bind the contacts to the required type as explained in onrosterstart.


Add New Roster

We can add new roster to the contacts list by using RosterManager in OnRoserItem

private void addNewRoster(Jid contactJid)


    objXmpp.RosterManager.AddRosterItem(contactJid); // Add new

    objXmpp.RosterManager.UpdateRosterItem(contactJid, "nickname"); //update

    objXmpp.RosterManager.RemoveRosterItem(contactJid); // remove


Approve Subscription

We can approve subscription according to the above mentioned subscription type

private void subcribeRoster(Jid contactJid)




OnRosterEnd handler is shown below
private void objXmpp_OnRosterEnd(object sender)



This handler assures that all Roster all delivered.

(Note: - We cannot use any controls in these handlers to display or update values. Since, these handlers are asynchronous.)

In Part 1 we discussed about Login and Login failed handler.

In Part 2 we discussed about Roster Handlers

And , In Part 3 we shall discuss about sending and Receiving Messages using AgsXmpp.


Understanding how to create and Install Windows Services in C#.Net

Windows Service in C#:This article is about how to create a Windows Service in C# .net using Visual ...

Read More >

What are Frames? How to handle frames in Selenium WebDriver with C#?

IFrame (FullForm: Inline Frame) is an HTML document that is included in another HTML document and is...

Read More >

What is Synchronization? Handling Synchronization in Selenium WebDriver using C#:

Synchronization meaning: when two or more components involved to perform any action, we expect these...

Read More >

Sending Test reports by Email using Office 365, Gmail

Wouldn’t it be great if Test Report are sent automatically across team as soon the Test Execut...

Read More >

Token Based Authentication for Web API's

Securing ASP.NET Web API using Custom Token Based AuthenticationProviding a security to the Web API&...

Read More >

Extent Reports in Selenium CSharp (C#)

Reports play a fundamental role when it comes to TESTING. Tester can now  know the real-time r...

Read More >

How to Set Up Selenium WebDriver in Visual Studio Enterprise 2015?

Pre-requisite : Visual Studio Enterprise 2015 application should be installed into the system.Create...

Read More >

Custom Control in WPF

File Upload Custom Control in WPFThis article is about Custom control in WPF, Custom controls are al...

Read More >

ASP.NET: Audit Trail Implementation using Entity Framework

When you are working with certain projects which involves the Customer records, you might need to tr...

Read More >

Create Restful service using Web API

What is Asp.Net Web API?Asp.Net Web API is a framework for building HTTP services that can be consum...

Read More >


Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive

Contact Us
  • *
  • *