Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Dhanu #1
Member since Aug 2007 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to Send a Chat msg from a C# app to a GTalk client
Hi All,

I need to send a simple text message from a C# (VS 2005) Windows application to a GTalk Client.
Nothing fancy, just open the conn, send msg, close conn. That's it.

I already have this code

XmppClientConnection xmpp = new XmppClientConnection();
xmpp.Server = "gmail.com";
xmpp.ConnectServer = "talk.google.com";
xmpp.Username = "your Gmail Account";
xmpp.Password = "your Password";
xmpp.Open();

 and

xmpp.Close()

Only thing I need to know is how to send the msg.
I someone has a simple sample code, plz share it with me.

Thanks in advance :-)
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Please take a look at the MiniClient example in frmChat.cs.
There is all you need an much more.

Alex
Avatar
Dhanu #3
Member since Aug 2007 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the reply.
Yes, I'm still looking at that code in MiniClient. (frmChat.cs)
But there is too much info that I can't figure it out.

XmppClientConnection xmpp = new XmppClientConnection();
xmpp.Server = "gmail.com";
xmpp.ConnectServer = "talk.google.com";
xmpp.Username = "your Gmail Account";
xmpp.Password = "your Password";
xmpp.Open();

agsXMPP.Jid JID = new Jid("test@gmail.com");
xmpp.MesagageGrabber.Add(JID, new agsXMPP.Collections.BareJidComparer(), new MessageCB(MessageCallback), null);

agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
msg.Type = agsXMPP.protocol.client.MessageType.chat;
msg.To = JID;
msg.Body = "www.mydomain.edu " + DateTime.Now.ToString();

xmpp.Send(msg);

this is the code that I have constructed so far.
When I add a watch to Authenticated property of xmpp object it's value is 'false'., even after the xmpp.Open() has been executed.
Does this mean that the connection has failed.

If possible I'm looking for a simple code segment to achieve my goal.
This post was edited on 2007-08-01, 20:52 by Dhanu.
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have to wait until you are logged in to the server.
The open method is asynchronous. Wait for the OnLogin Event before you send your message.

Alex
Avatar
Dhanu #5
Member since Aug 2007 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex.
I was able to get it working now.

I'll just post the code I used here, so that others can make use of it

XmppClientConnection xmpp = new XmppClientConnection();
xmpp.Server = "gmail.com";
xmpp.ConnectServer = "talk.google.com";
xmpp.Username = "your Gmail Account";
xmpp.Password = "your Password";
xmpp.Open();

agsXMPP.Jid JID = new Jid("test@gmail.com");
xmpp.MesagageGrabber.Add(JID, new agsXMPP.Collections.BareJidComparer(), new MessageCB(MessageCallback), null);

agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
msg.Type = agsXMPP.protocol.client.MessageType.chat;
msg.To = JID;
msg.Body = "www.mydomain.edu " + DateTime.Now.ToString();

xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); };
Avatar
Alex #6
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
if you are not on CF and set AutoResolveConnectServer = true there is no need to specify the connect server (talk.google.com).

Alex
Avatar
Chandan Das #7
Member since Jan 2013 · 1 post
Group memberships: Members
Show profile · Link to this post
Hi i used the code mentioned here but not able to send message. I am using .net 4.0.
Avatar
Alex #8
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Download MatriX from here:
http://www.ag-software.net/matrix-xmpp-sdk/download/

and run the MiniClient example with your GTalk credentials. It definitely works.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS