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";
}
}
}
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";
}
}
}