Reputation: 67
I am trying to make an agsXMPP GTalk chat client in Asp.Net but the OnLogin event is just not doing anything at all, I have tried so, so many things...
Can anyone please help me?
Here is the code for the aspx.cs file:
using System;
...
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using System.Threading;
using Microsoft.Win32;
public partial class ChatClient : System.Web.UI.Page
{
private agsXMPP.XmppClientConnection xmppCC = new XmppClientConnection();
protected void Page_Load(object sender, EventArgs e)
{
}
void xmpp_OnLogin(object sender)
{
lblMsg.Text = "Succes!" + xmppCC.Authenticated.ToString();
xmppCC.SendMyPresence();
}
string emailAdres; string password;
protected void cmdLogin_Click(object sender, EventArgs e)
{
emailAdres = textEmail.Text; password= textPassw.Text;
xmppCC = (XmppClientConnection)Application["xmpp"];
if (xmppCC == null)
{
xmppCC = new XmppClientConnection();
Application["xmpp"] = xmppCC;
}
Jid jidSender = new Jid(emailAdres);
xmppCC.Username = jidSender.User;
xmppCC.Server = jidSender.Server;
xmppCC.Password = password;
xmppCC.AutoResolveConnectServer = true;
try
{
xmppCC.OnLogin += xmpp_OnLogin;
lblMsg.Text = "";
xmppCC.Open();
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
}
}
Thanks in advance
Upvotes: 0
Views: 1203
Reputation: 4136
I suggest to combine it with a realtime HTTP channel like SignalR. See also my blog post here: http://www.ag-software.net/2012/08/20/web-clients-with-matrix-and-signalr/
Upvotes: 0
Reputation: 5266
xmppCC.Server
is not always equal to jidSender.Server
, to auto resolve Server
try this:
emailAdres = textEmail.Text; password= textPassw.Text;
xmppCC = (XmppClientConnection)Application["xmpp"];
Jid jidSender = new Jid(emailAdres);
if (xmppCC == null)
{
xmppCC = new XmppClientConnection(jidSender.Server);
Application["xmpp"] = xmppCC;
}
// xmppCC.Username = jidSender.User;
// xmppCC.Server = jidSender.Server; it will be resolved with AutoResolveConnectServer = true
// xmppCC.Password = password;
xmppCC.AutoResolveConnectServer = true;
xmppCC.OnLogin += s => Debug.WriteLine("Logged in");
xmppCC.Open(jidSender.User, password);
Upvotes: 2