Click here to Skip to main content
13,291,254 members (61,710 online)
Click here to Skip to main content
Add your own
alternative version


112 bookmarked
Posted 19 Mar 2009

Google Chat Desktop Application using Jabber.Net

, 20 Mar 2009
Rate this:
Please Sign up or sign in to vote.
A simple Google chat ( gtalk ) application using Jabber.Net


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.


This application is developed using a .NET open source library, 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 = "";
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.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:


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;
            string sentMsg = _jabberClient.User + " Says : " + 
					rtbSendMessage.Text + "\n";
            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";
               msg.Body = "";


  • Released in March 2009


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


About the Author

Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

Questionlogin unsuccessful Pin
Member 1306360017-Mar-17 4:07
memberMember 1306360017-Mar-17 4:07 
QuestionDoes this still work with the new hangouts ? Pin
NikoTanghe19-May-16 9:29
memberNikoTanghe19-May-16 9:29 
QuestionCan this app be used with another server? Pin
Member 1174653827-Nov-15 17:20
memberMember 1174653827-Nov-15 17:20 
QuestionAutoreply not working Pin
Member 805727312-Oct-15 22:29
memberMember 805727312-Oct-15 22:29 
QuestionNeed help setting Subscription to "both" Pin
Member 1047794224-Feb-15 16:25
memberMember 1047794224-Feb-15 16:25 
Questioncan we send or receive files like messages? Pin
shashank76814-Dec-14 20:25
membershashank76814-Dec-14 20:25 
Questionsend images Pin
kazemfallahi137117-Sep-13 4:15
memberkazemfallahi137117-Sep-13 4:15 
GeneralMy vote of 5 Pin
Member 919827214-Jun-13 22:56
memberMember 919827214-Jun-13 22:56 
Questionaltering it Pin
Keith Aiden17-May-13 7:16
memberKeith Aiden17-May-13 7:16 
QuestionThe user name and password login unsuccessful Pin
lanyan_hhb29-Jan-13 16:20
memberlanyan_hhb29-Jan-13 16:20 
AnswerRe: The user name and password login unsuccessful Pin
Member 1306360018-Mar-17 4:32
memberMember 1306360018-Mar-17 4:32 
QuestionAny updates? Pin
kiquenet.com18-Jan-13 2:38
memberkiquenet.com18-Jan-13 2:38 
QuestionJoin Group Chat Pin
tithsochinda10-Jan-13 0:28
membertithsochinda10-Jan-13 0:28 
Dear sir,

This is is very good, but I cannot find how to join chat room in your example,
so please let me know how can I join chat room.

I'm looking for your reply,
Thanks in advanced
GeneralMy vote of 5 Pin
Ankita M5-Nov-12 0:10
memberAnkita M5-Nov-12 0:10 
QuestionCan We Get Previously Set Status Message Pin
karthikeyanthangavel2-Nov-12 0:35
memberkarthikeyanthangavel2-Nov-12 0:35 
GeneralMy vote of 5 Pin
gaga blues22-Oct-12 5:13
membergaga blues22-Oct-12 5:13 
GeneralMy vote of 5 Pin
arunraju2-Aug-12 0:02
memberarunraju2-Aug-12 0:02 
QuestionDoubt Pin
SIVA111118-Jul-12 1:10
memberSIVA111118-Jul-12 1:10 
QuestionStatus Pin
Infinity82717-Apr-12 12:21
memberInfinity82717-Apr-12 12:21 
AnswerRe: Status Pin
naoufal zerai18-Aug-12 20:07
membernaoufal zerai18-Aug-12 20:07 
GeneralRe: Status Pin
Infinity82719-Aug-12 11:59
memberInfinity82719-Aug-12 11:59 
GeneralRe: Status Pin
naoufal zerai24-Aug-12 12:28
membernaoufal zerai24-Aug-12 12:28 
GeneralRe: Status Pin
Infinity82724-Aug-12 15:41
memberInfinity82724-Aug-12 15:41 
GeneralRe: Status Pin
naoufal zerai30-Aug-12 4:46
membernaoufal zerai30-Aug-12 4:46 
GeneralRe: Status Pin
Infinity82730-Aug-12 12:33
memberInfinity82730-Aug-12 12:33 
QuestionBug on incoming message Pin
Member 826597110-Feb-12 8:14
memberMember 826597110-Feb-12 8:14 
GeneralMy vote of 4 Pin
andrewsroys19-Jan-12 23:35
memberandrewsroys19-Jan-12 23:35 
QuestionShow only online contacts or online contacts on top Pin
divac1218-Jan-12 13:45
memberdivac1218-Jan-12 13:45 
GeneralMy vote of 5 Pin
konduc14-Jun-11 2:41
memberkonduc14-Jun-11 2:41 
GeneralMy vote of 5 Pin
NetDave30-Mar-11 11:28
memberNetDave30-Mar-11 11:28 
QuestionHow to get offline messges functionality Pin
Arif_Madi29-Mar-11 23:08
memberArif_Madi29-Mar-11 23:08 
AnswerRe: How to get offline messges functionality Pin
NetDave30-Mar-11 11:27
memberNetDave30-Mar-11 11:27 
GeneralRe: How to get offline messges functionality Pin
Arif_Madi30-Mar-11 21:21
memberArif_Madi30-Mar-11 21:21 
QuestionWorks in default : Having Issues connecting to OpenFire Pin
Member 779629929-Mar-11 8:59
memberMember 779629929-Mar-11 8:59 
GeneralWorking like a charm Pin
Tae-Sung22-Feb-11 11:22
memberTae-Sung22-Feb-11 11:22 
GeneralCode is understanable. Pin
garysprice12-Aug-10 23:05
membergarysprice12-Aug-10 23:05 
GeneralMy vote of 1 Pin
sunilkumarmano7-Jul-10 4:20
membersunilkumarmano7-Jul-10 4:20 
GeneralRe: My vote of 1 Pin
Lloyd Atkinson12-Dec-10 8:24
memberLloyd Atkinson12-Dec-10 8:24 
GeneralUsing Openfire in localmachine Pin
Christatos30-Jun-10 1:28
memberChristatos30-Jun-10 1:28 
GeneralCreate new account Pin
sr_dusad19-Apr-10 3:16
membersr_dusad19-Apr-10 3:16 
Generalabout adding contacts option in gtalk application Pin
nitin sanap8-Mar-10 20:06
membernitin sanap8-Mar-10 20:06 
GeneralGoogle Chat Application for Windows Mobile using Jabber.Net Pin
jaiswalrahul26-Jan-10 21:40
memberjaiswalrahul26-Jan-10 21:40 
GeneralHI i need a local chet app like gmail Pin
Sravani54930-Oct-09 3:35
memberSravani54930-Oct-09 3:35 
QuestionNo Contacts are displayed in the Roster Pin
pilla G Patrudu1-Aug-09 2:39
memberpilla G Patrudu1-Aug-09 2:39 
AnswerRe: No Contacts are displayed in the Roster Pin
$enthi£5-Aug-09 5:07
member$enthi£5-Aug-09 5:07 
GeneralComponent for VS 2008 Pin
Anand KG23-Jul-09 20:15
memberAnand KG23-Jul-09 20:15 
Generalplease help Pin
deeps108-Jul-09 1:33
memberdeeps108-Jul-09 1:33 
AnswerRe: please help Pin
$enthi£5-Aug-09 5:06
member$enthi£5-Aug-09 5:06 
QuestionChat Group? Pin
i-developer of Istanbul12-Jun-09 2:20
memberi-developer of Istanbul12-Jun-09 2:20 
AnswerRe: Chat Group? Pin
$enthi£5-Aug-09 5:04
member$enthi£5-Aug-09 5:04 

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