Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
polarwyp #1
Member since May 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: agsXMPP on WM5
Hi!

I try to use agsXMPP to connect GoogleTalk server on Windows Mobile 5 but it just give me an OnClose message?

I'm sure my WM Emulator is connet to the Internet.

The related code is just below:

            Jid jidUser = new Jid("yunpeng.soft@gmail.com");

            xmppCon.Username = jidUser.User;
            xmppCon.Server = jidUser.Server;
            xmppCon.Password = "aa";
            xmppCon.AutoResolveConnectServer = true;
            xmppCon.ConnectServer = "talk.google.com";

            xmppCon.Open();


After called open() method, I just got an OnClose message istead of OnLogin or OnAuthError message.

Can you help me to solve this problem, thank you!

The full code is copied below(this code works well on the Windows PC, modified just a little from the GTalk sample):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using agsXMPP;

namespace MiniGTalk
{
    public partial class frmMain : Form
    {
        XmppClientConnection xmppCon = new XmppClientConnection();

        public frmMain()
        {
            InitializeComponent();

            Init();
        }

        private void Init()
        {
            // Subscribe to Events
            xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
             xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
             xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
             xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
             xmppCon.OnPresence += new agsXMPP.protocol.client.PresenceHandler(xmppCon_OnPresence);
             xmppCon.OnAuthError += new XmppElementHandler(xmppCon_OnAuthError);
             xmppCon.OnError += new ErrorHandler(xmppCon_OnError);
             xmppCon.OnClose += new ObjectHandler(xmppCon_OnClose);
             xmppCon.OnMessage += new agsXMPP.protocol.client.MessageHandler(xmppCon_OnMessage);
        }

        void xmppCon_OnLogin(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnLogin), new object[] { sender });
                return;
            }
            txtBox.Text += "OnLogin\n";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Jid jidUser = new Jid("yunpeng.soft@gmail.com");

            xmppCon.Username = jidUser.User;
            xmppCon.Server = jidUser.Server;
            xmppCon.Password = "aa";
            xmppCon.AutoResolveConnectServer = true;
            xmppCon.ConnectServer = "talk.google.com";

            xmppCon.Open();
            txtBox.Text += "Open\n";

        }

        void xmppCon_OnError(object sender, Exception ex)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ErrorHandler(xmppCon_OnError), new object[] { sender, ex });
                return;
            }
            txtBox.Text += "OnError\n";
        }

        void xmppCon_OnAuthError(object sender, agsXMPP.Xml.Dom.Element e)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new XmppElementHandler(xmppCon_OnAuthError), new object[] { sender, e });
                return;
            }
            txtBox.Text += "OnAuthError\n";
        }

        void xmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            // ignore empty messages (events)
            if (msg.Body == null)
                return;

            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new agsXMPP.protocol.client.MessageHandler(xmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

//             listEvents.Items.Add(String.Format("OnMessage from:{0} type:{1}", msg.From.Bare, msg.Type.ToString()));
//             listEvents.Items.Add(msg.Body);
            txtBox.Text += "OnMessage\n";
        }

        void xmppCon_OnClose(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnClose), new object[] { sender });
                return;
            }
            txtBox.Text += "OnClose\n";
        }

        void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new agsXMPP.protocol.client.PresenceHandler(xmppCon_OnPresence), new object[] { sender, pres });
                return;
            }
            txtBox.Text += "OnPresence\n";
        }

        void xmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem), new object[] { sender, item });
                return;
            }
            txtBox.Text += "OnRosterItem\n";
        }

        void xmppCon_OnRosterEnd(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnRosterEnd), new object[] { sender });
                return;
            }
            txtBox.Text += "OnRosterEnd\n";

            // Send our own presence to teh server, so other epople send us online
            // and the server sends us the presences of our contacts when they are
            // available
            xmppCon.SendMyPresence();
        }

        void xmppCon_OnRosterStart(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnRosterStart), new object[] { sender });
                return;
            }
            txtBox.Text += "OnRosterStart\n";
        }
    }
}
Avatar
Jabberer #2
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
AutoResolveConnectServer must be false. The rest looks fine.
Software Developer
AG-Software
This post was edited on 2008-05-14, 07:55 by Jabberer.
Avatar
polarwyp #3
Member since May 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
I changed AutoResolveConnectServer to false, but the problem is still.

maybe there is something wrong with my project settings? or something wrong with my deployment?

I tryed the MiniClientWM5 sample on my emulator, on the Debug page, I only got the following XML:

SEND:<stream:stream to='gmail.com' xmlns='jabber:client' xmlns:stream='http://eherx.jabber.org/streams' version='1.0' xml:lang='en'>

and no response from the server.
Avatar
polarwyp #4
Member since May 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
The problem had been solved!

I changed the AutoResolveConnectServer to false and the ConnectServer to 'talk3.l.google.com', it worked!

Thanks to Jabberer!
Avatar
Jabberer #5
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
great, talk.google.com always worked before. Maybe the server is down at the moment.
Its still the recommended server on the Google Help pages. eg. here: http://www.google.com/support/talk/bin/answer…?answer=24…

But all servers listed in the SRV records for xmpp-client.tcp.gmail.com should work

dig @ns1.google.com _xmpp-client._tcp.gmail.com SRV

; <<>> DiG 9.3.2 <<>> @ns1.google.com _xmpp-client._tcp.gmail.com SRV
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40458
;; flags: qr aa rd; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 4

;; QUESTION SECTION:
;_xmpp-client._tcp.gmail.com.   IN      SRV

;; ANSWER SECTION:
_xmpp-client._tcp.gmail.com. 86400 IN   SRV     20 0 5222 talk3.l.google.com.
_xmpp-client._tcp.gmail.com. 86400 IN   SRV     20 0 5222 talk4.l.google.com.
_xmpp-client._tcp.gmail.com. 86400 IN   SRV     5 0 5222 talk.l.google.com.
_xmpp-client._tcp.gmail.com. 86400 IN   SRV     20 0 5222 talk1.l.google.com.
_xmpp-client._tcp.gmail.com. 86400 IN   SRV     20 0 5222 talk2.l.google.com.

;; AUTHORITY SECTION:
gmail.com.              345600  IN      NS      ns1.google.com.
gmail.com.              345600  IN      NS      ns2.google.com.
gmail.com.              345600  IN      NS      ns3.google.com.
gmail.com.              345600  IN      NS      ns4.google.com.

;; ADDITIONAL SECTION:
ns1.google.com.         345600  IN      A       216.239.32.10
ns2.google.com.         345600  IN      A       216.239.34.10
ns3.google.com.         345600  IN      A       216.239.36.10
ns4.google.com.         345600  IN      A       216.239.38.10

;; Query time: 181 msec
;; SERVER: 216.239.32.10#53(216.239.32.10)
;; WHEN: Wed May 14 11:31:03 2008
;; MSG SIZE  rcvd: 377
Software Developer
AG-Software
Avatar
DKhanh #6
Member since Mar 2011 · 5 posts
Group memberships: Members
Show profile · Link to this post
I have a same problem with polarwyp,
Here is my log
[Image: http://img814.imageshack.us/img814/3747/captureazl.png]
I don't know how to copy text from emulator to clipboard, so I capture screen.

here is my source code
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using agsXMPP;

namespace SmartDeviceProject2
{
    public partial class Form1 : Form
    {
        XmppClientConnection xmppCon = new XmppClientConnection();
        public Form1()
        {
            InitializeComponent();

            // Subscribe to Events
            xmppCon.OnReadXml += new XmlHandler(XmppCon_OnReadXml);
            xmppCon.OnWriteXml += new XmlHandler(XmppCon_OnWriteXml);

            xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
            xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
            xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
            xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
            xmppCon.OnPresence += new agsXMPP.protocol.client.PresenceHandler(xmppCon_OnPresence);
            xmppCon.OnAuthError += new XmppElementHandler(xmppCon_OnAuthError);
            xmppCon.OnError += new ErrorHandler(xmppCon_OnError);
            xmppCon.OnClose += new ObjectHandler(xmppCon_OnClose);
            xmppCon.OnMessage += new agsXMPP.protocol.client.MessageHandler(xmppCon_OnMessage);
        }

        void xmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            // ignore empty messages (events)
            if (msg.Body == null)
                return;

            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new agsXMPP.protocol.client.MessageHandler(xmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            listEvents.Items.Add(String.Format("OnMessage from:{0} type:{1}", msg.From.Bare, msg.Type.ToString()));
            listEvents.Items.Add(msg.Body);
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        void xmppCon_OnClose(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnClose), new object[] { sender });
                return;
            }
            listEvents.Items.Add("OnClose Connection closed");
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        void xmppCon_OnError(object sender, Exception ex)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ErrorHandler(xmppCon_OnError), new object[] { sender, ex });
                return;
            }
            listEvents.Items.Add("OnError " + ex.Message);
            txtDebug.Text += ("OnError " + ex.Message);
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        void xmppCon_OnAuthError(object sender, agsXMPP.Xml.Dom.Element e)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new XmppElementHandler(xmppCon_OnAuthError), new object[] { sender, e });
                return;
            }
            listEvents.Items.Add("OnAuthError");
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new agsXMPP.protocol.client.PresenceHandler(xmppCon_OnPresence), new object[] { sender, pres });
                return;
            }
            listEvents.Items.Add(String.Format("Received Presence from:{0} show:{1} status:{2}", pres.From.ToString(), pres.Show.ToString(), pres.Status));
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        void xmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem), new object[] { sender, item });
                return;
            }
            listEvents.Items.Add(String.Format("Received Contact {0}", item.Name));
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        void xmppCon_OnRosterEnd(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnRosterEnd), new object[] { sender });
                return;
            }
            listEvents.Items.Add("OnRosterEnd");
            listEvents.SelectedIndex = listEvents.Items.Count - 1;

            // Send our own presence to teh server, so other epople send us online
            // and the server sends us the presences of our contacts when they are
            // available
            xmppCon.SendMyPresence();
        }

        void xmppCon_OnRosterStart(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnRosterStart), new object[] { sender });
                return;
            }
            listEvents.Items.Add("OnRosterStart");
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        void xmppCon_OnLogin(object sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new ObjectHandler(xmppCon_OnLogin), new object[] { sender });
                return;
            }
            listEvents.Items.Add("OnLogin");
            listEvents.SelectedIndex = listEvents.Items.Count - 1;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
        private void XmppCon_OnReadXml(object sender, string xml)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new XmlHandler(XmppCon_OnReadXml), new object[] { sender, xml });
                return;
            }

            txtDebug.SelectionStart = txtDebug.Text.Length;
            txtDebug.Text += ("RECV:" + xml + "\r\n");
            txtDebug.SelectionStart = txtDebug.Text.Length;
            txtDebug.ScrollToCaret();
        }

        private void XmppCon_OnWriteXml(object sender, string xml)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke               
                BeginInvoke(new XmlHandler(XmppCon_OnWriteXml), new object[] { sender, xml });
                return;
            }
            txtDebug.SelectionStart = txtDebug.Text.Length;
            txtDebug.Text += ("SEND:" + xml + "\r\n");
            txtDebug.SelectionStart = txtDebug.Text.Length;
            txtDebug.ScrollToCaret();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Jid jidUser = new Jid("BC0508AC@gmail.com");

            xmppCon.Username = jidUser.User;
            xmppCon.Server = jidUser.Server;
            xmppCon.Password = "`12`12`12";
            xmppCon.AutoResolveConnectServer = false;
            xmppCon.UseStartTLS = false;
            xmppCon.ConnectServer = "talk.google.com";

            xmppCon.Open();
        }
    }
}
Avatar
Alex #7
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
can you post your complete Xml log?
Your Screenshot shows an OnError event, can you post the error or full stacktrace?

Alex
Avatar
DKhanh #8
Member since Mar 2011 · 5 posts
Group memberships: Members
Show profile · Link to this post
if i don't specify ConnectServer ""talk.google.com", no xmppCon even occur and xml log are not written
this is full log xml
SEND:<stream:stream to='gmail.com' xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams' version='1.0'
xml:lang='en'>
RECV:<stream:stream xmlns:stream="http://etherx.jabber.org/streams"
from="gmail.com" version="1.0" id="EF7FFA2C751A6CEA" >
RECV:<stream:features
xmlns:stream="http://etherx.jabber.org/streams"><starttls
xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required
/></starttls><mechanisms
xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-GOOGLE-TOKEN</mechanism></mechanisms></stream:features>

and Error stack track

OnError at System.Net.HttpWebRequest.startGetRequestStream()
at System.Net.HttpWebRequest.BeginGetRequestStream()
at agsXMPP.sasl.XGoogleToken.XGoogleTokenMechanism.DoClientAuth()
at agsXMPP.sasl.XGoogleToken.XGoogleTokenMechanism.Init()
at agsXMPP.sasl.SaslHandler.OnStreamElement()
at agsXMPP.Xml.StreamParser.DoRaiseOnStreamElement()
at agsXMPP.Xml.StreamParser.EndTag()
at agsXMPP.Xml.StreamParser.Push()
at agsXMPP.XmppConnection.SocketOnReceive()
at agsXMPP.net.BaseSocket.FireOnReceive()
at agsXMPP.net.ClientSocket.EndReceive()
at System.Net.LazyAsyncResult.InvokeCallback()
at WorkerThread.doWork()
at WorkerThread.doWorkI()
at WorkItem.doWork()
at System.Threading.Timer.ring()

why don't you try to run my code in vs 2008 with windows mobile sdk 6
This post was edited on 2011-03-22, 11:52 by DKhanh.
Avatar
Alex #9
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
  • Make sure that you use the latest SVN code
  • I don't test under WM5, only WM6 and newer

There is no TLS support in the CF which caused often problems with GTalk. And it seems that the Webrequests for the Google-X-Token authentication fail or timeout randomly.
Avatar
DKhanh #10
Member since Mar 2011 · 5 posts
Group memberships: Members
Show profile · Link to this post
Can you share your code under wm6
Avatar
Alex #11
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
All my code is in the MiniClient example. I use it without modifications for testing.

Alex
Avatar
DKhanh #12
Member since Mar 2011 · 5 posts
Group memberships: Members
Show profile · Link to this post
Yeah, but miniClient is for windows app, not for mobile app. And MiniClientWM5 doesnot work, I go to menu File/Connect, input gmail account and hit Login button but nothing happen, xml log is not output in Debug or Socket Debug tab.
Your lastest SVN code was update on Nov 16, 2010. Are you sure that it still works good, at least with gmail?
This post was edited on 2011-03-24, 07:58 by DKhanh.
Avatar
Alex #13
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
in the download there is a MiniClient for Windows Mobile included.
Avatar
DKhanh #14
Member since Mar 2011 · 5 posts
Group memberships: Members
Show profile · Link to this post
And MiniClientWM5 doesnot work too, I go to menu File/Connect, input gmail account and hit Login button but nothing happen, xml log is not output in Debug or Socket Debug tab.
Avatar
Alex #15
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I've attached the WM6 example which always worked for me.
As I said before there were reports that it randomly fails. The problem is that there is no Tls support in the Compact Framework and GTalk requires either Tls or X-Token-Authentication. And its not likely that Microsoft will release an update to the Compact Framework with TLS.
If you must connect to GTalk then I suggest to use the MatriX library which supports TLS on WM6 and WM6.5
The author has attached one file to this post:
MiniClientWM6.zip 39.8 kBytes
You have no permission to open this file.
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