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

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
  • TLS
  • SASL
  • IM
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

There are many providers who had built in libraries as mentioned in XMPP Standard foundation check linkhttp://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 ag-software.net 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: 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.

 

Tags: 
Filed Under: 

Comments

cartier pasha uomo's picture
By cartier pasha uomo (Anonymous) on
So true, dequik2, their homes are too far away. Besides, they might like it here. During WW II, Italian POWs had to be pried out of here with a crowbar when the war ended. They LOVED it here! cartier pasha uomo http://www.aaawatch.cn/it/pasha-watch-series-c94/

Dhrumil.'s picture
By Dhrumil. (Anonymous) on
I don't have a server name, instead it shows some ip address. I tried using the name in the spark but wasnt able to connect but i was able to connect using the i.p address.

love bangle 2016 copy's picture
By love bangle 201... (Anonymous) on
cartierlovejesduas I often get that reply, that I’m too close to it to really know, and people seem much more willing to believe this (despite knowing that 5 minutes with me in person would show you I am not some spiritual crack pot steiner), rather than believing that they have had a bad experience, or that people who don’t like steiner are giving them evidence which supports a negative view, completely biased. It’s like basing your view of Christianity on child molestation as opposed to love, peace and compassion, despite the act that three of those are much, much more common. love bangle 2016 copy http://www.beauty-bracelet.com/

van cleef collana cuore imitazione's picture
By van cleef colla... (Anonymous) on
cartierbraceletlove I couldn’t do the challenge, but I sure did enjoy going thru your article! Now I want to go back thru the article and zero in on some of the related blogs. Thanks, AJ. van cleef collana cuore imitazione http://www.vancleef-jewelry.cn/it/

Add new comment