C# agsXMPP OnLogin事件未触发Asp.Net
我正在尝试在Asp.Net中创建一个agsXMPP GTalk聊天客户端,但是OnLogin事件根本没有做任何事情,我已经尝试了很多事情 有人能帮我吗 以下是aspx.cs文件的代码:C# agsXMPP OnLogin事件未触发Asp.Net,c#,asp.net,xmpp,google-talk,agsxmpp,C#,Asp.net,Xmpp,Google Talk,Agsxmpp,我正在尝试在Asp.Net中创建一个agsXMPP GTalk聊天客户端,但是OnLogin事件根本没有做任何事情,我已经尝试了很多事情 有人能帮我吗 以下是aspx.cs文件的代码: using System; ... using agsXMPP; using agsXMPP.protocol.client; using agsXMPP.Collections; using agsXMPP.protocol.iq.roster; using System.Threading; using
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;
}
}
}
提前感谢
xmppCC.Server
并不总是等于jidSender.Server
,要自动解析Server
,请尝试以下操作:
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);
我建议将其与实时HTTP通道(如信号器)相结合。请参见我的博客帖子:
它实际上没有做任何新的事情,只是现在当我键入地址时,它会将其保存在永久的位置,因此当我键入另一个地址时,服务器保持不变(例如,我键入x@x.x那么wt@gmail.com,它会把它变成wt@x.x)如果您使用的是Google Talk帐户,然后
xx@gmail.com
帐户应解析为talk.google.com
服务器调试期间我在哪里可以看到它?我不确定您是否正确使用了agsXMPP。agsXMPP必须打开到服务器的TCP连接并保持其打开状态。如果你在Web.UI.Page
上实例化连接,它将在加载页面后立即被销毁。它说连接服务器是“xmpp.l.google.com”,我也一直在按照同样的方法来做。