Click here to Skip to main content
Licence Public Domain
First Posted 19 Mar 2009
Views 113,481
Downloads 5,598
Bookmarked 87 times

Google Chat Desktop Application using Jabber.Net

By | 20 Mar 2009 | Article
A simple Google chat ( gtalk ) application using Jabber.Net
Gtalk_Messenger.jpg

Introduction

This is a simple Google chat ( gtalk ) desktop application developed in C#. With this application, we can easily chat with our Gmail contacts. This application serves as a best approach for developers to start with the chat application for Gmail.

Background

This application is developed using a .NET open source library, Jabber.net. This library contains a set of .NET controls for sending and receiving extensible messaging and presence protocol (XMPP), also known as the Jabber.

Using the Code

After installing the Jabber.Net library, you can see the list of Jabber.Net controls in the Visual Studio toolbox. Now, add the JabberClient control to the form and assign the user name and password.

User = txtUserName.Text;
Pwd = txtPassword.Text;
jabberClient1.User = User;
jabberClient1.Server = "gmail.com";
jabberClient1.Password = Pwd;
jabberClient1.AutoRoster = true;

Now, add a RosterTree control to populate the contact list and assign the instance of the roster manager and the presence manager to the roster tree control.

rm = new RosterManager();
rm.Stream = jabberClient1;
rm.AutoSubscribe = true;
rm.AutoAllow = jabber.client.AutoSubscriptionHanding.AllowAll;
rm.OnRosterBegin += new bedrock.ObjectHandler(rm_OnRosterBegin);
rm.OnRosterEnd += new bedrock.ObjectHandler(rm_OnRosterEnd);
rm.OnRosterItem += new RosterItemHandler(rm_OnRosterItem);

The RosterManager will add the contact list to the roster tree and the PresenceManager will add a notification for the contact whether the contact is in online or offline mode.

pm = new PresenceManager();
pm.Stream = jabberClient1;

rosterTree1.RosterManager = rm;
rosterTree1.PresenceManager = pm;

After assigning all of the above, we have to call the connect() method to login with the given credentials and populate the roster tree with the contact list.

jabberClient1.Connect();
jabberClient1.OnAuthenticate += new bedrock.ObjectHandler(jabberClient1_OnAuthenticate);

On double clicking a contact in the contact list will open a chat window, through which the user can send messages using the following function:

Gtalk_chat.jpg

private void SendMessage()
{
	jabber.protocol.client.Message reply = 
		new jabber.protocol.client.Message(_jabberClient.Document);
    if (rtbSendMessage.Text != "\n" && rtbSendMessage.Text != " ")
    {
        reply.Body = rtbSendMessage.Text;
        if (reply.Body != "")
        {
            reply.To = _mailId;
            _jabberClient.Write(reply);
            string sentMsg = _jabberClient.User + " Says : " + 
					rtbSendMessage.Text + "\n";
            AppendConversation(sentMsg);
            rtbSendMessage.Text = "";
        }
    }            
}

The JabberClient is registered with an onMessage event to receive whenever an incoming message arrives. This is handled by the following function:

public void _jabberClient_OnMessage
	(object sender, jabber.protocol.client.Message msg)
{
   if (!this.ReceiveFlag)
   {
       if (msg.From.Bare == this.MailId)
       {
           if (msg.Body != "")
           {
               string receivedMsg = msg.From.User + " Says : " + msg.Body + "\n";
               AppendConversation(receivedMsg);
               msg.Body = "";
           }
       }
   }
}

History

  • Released in March 2009

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

About the Author

$enthi£

Software Developer

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionStatus PinmemberInfinity82711:21 17 Apr '12  
QuestionBug on incoming message PinmemberMember 82659717:14 10 Feb '12  
GeneralMy vote of 4 Pinmemberandrewsroys22:35 19 Jan '12  
QuestionShow only online contacts or online contacts on top Pinmemberdivac1212:45 18 Jan '12  
GeneralMy vote of 5 Pinmemberkonduc1:41 14 Jun '11  
GeneralMy vote of 5 PinmemberNetDave10:28 30 Mar '11  
QuestionHow to get offline messges functionality PinmemberArif_Madi22:08 29 Mar '11  
AnswerRe: How to get offline messges functionality PinmemberNetDave10:27 30 Mar '11  
GeneralRe: How to get offline messges functionality PinmemberArif_Madi20:21 30 Mar '11  
QuestionWorks in default : Having Issues connecting to OpenFire PinmemberMember 77962997:59 29 Mar '11  
GeneralWorking like a charm PinmemberTae-Sung10:22 22 Feb '11  
GeneralCode is understanable. Pinmembergarysprice22:05 12 Aug '10  
GeneralMy vote of 1 Pinmembersunilkumarmano3:20 7 Jul '10  
GeneralRe: My vote of 1 PinmemberLloyd Atkinson7:24 12 Dec '10  
GeneralUsing Openfire in localmachine PinmemberChristatos0:28 30 Jun '10  
GeneralCreate new account Pinmembersr_dusad2:16 19 Apr '10  
Generalabout adding contacts option in gtalk application Pinmembernitin sanap19:06 8 Mar '10  
GeneralGoogle Chat Application for Windows Mobile using Jabber.Net Pinmemberjaiswalrahul20:40 26 Jan '10  
GeneralHI i need a local chet app like gmail PinmemberSravani5492:35 30 Oct '09  
QuestionNo Contacts are displayed in the Roster Pinmemberpilla G Patrudu1:39 1 Aug '09  
AnswerRe: No Contacts are displayed in the Roster Pinmember$enthi£4:07 5 Aug '09  
GeneralComponent for VS 2008 PinmemberAnand KG19:15 23 Jul '09  
Generalplease help Pinmemberdeeps100:33 8 Jul '09  
AnswerRe: please help Pinmember$enthi£4:06 5 Aug '09  
QuestionChat Group? Pinmemberi-developer of Istanbul1:20 12 Jun '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120517.1 | Last Updated 21 Mar 2009
Article Copyright 2009 by $enthi£
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid