我正在尝试在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 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;
}
}
}
提前致谢
答案 0 :(得分:2)
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);
答案 1 :(得分:0)
我建议将它与SignalR等实时HTTP通道结合使用。另见我的博客文章: http://www.ag-software.net/2012/08/20/web-clients-with-matrix-and-signalr/