Subject: Retrieving messages through a web client
Hello Alex and community,
First, I love the library you have built, and I wanted to let you know that we are building a Jabber/XMPP chat for our website of 4 million users using agsXMPP. (Is it the biggest implementation?) For the entire day today I've been trying to figure out why I can't get any messages to show up anywhere in the rapid prototype I'm making. I can login and logout and send a message. Ultimately, I want to long poll the received messages, but for now I'm happy just using a timed UpdatePanel so I can get a feel of sending and receiving. Here is my code:
//////////////////////Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="LoginButton" runat="server" Text="Login"
onclick="LoginButton_Click" />
<asp:Button ID="LogoutButton" runat="server" onclick="LogoutButton_Click"
Text="Logout" />
<br />
<br />
To:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
Message:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="SendMessage1" runat="server" Text="Send"
onclick="SendMessage1_Click" />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="GetMessages.aspx">Get New Messages</asp:HyperLink>
</div>
<asp:Label ID="Log" runat="server"></asp:Label>
<asp:Label ID="Log2" runat="server"></asp:Label>
<div id="chat">
</div>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Chat" runat="server" Text="Chat"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
////////////////////////Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using System.Threading;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private static XmppClientConnection xmpp;
string ConstructJID(string username)
{
string JID = username + "@comp6";
return JID;
}
public static string Username = "1";
public static string Password = "1";
protected void LoginButton_Click(object sender, EventArgs e)
{
xmpp = (XmppClientConnection)Cache["xmpp"];
if (xmpp == null)
{
xmpp = new XmppClientConnection();
Cache["xmpp"] = xmpp;
}
xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
xmpp.OnError += new ErrorHandler(xmpp_OnError);
xmpp.Port = 5222;
xmpp.UseSSL = false;
xmpp.Server = "comp6";
xmpp.Username = Username;
xmpp.Password = Password;
try
{
xmpp.Open();
Log.Text = "Logged in.";
}
catch (Exception ex)
{
Log.Text = ex.Message;
}
}
void xmpp_OnError(object sender, Exception ex)
{
}
void xmpp_OnLogin(object sender)
{
xmpp.SendMyPresence();
}
protected void LogoutButton_Click(object sender, EventArgs e)
{
XmppClientConnection xmpp = (XmppClientConnection)Cache["xmpp"];
try
{
xmpp.Close();
Cache.Remove("xmpp");
Log.Text = "Logged out.";
}
catch (Exception ex)
{
Log.Text = ex.Message;
}
}
protected void SendMessage1_Click(object sender, EventArgs e)
{
XmppClientConnection xmpp = (XmppClientConnection)Cache["xmpp"];
string ToUser = TextBox1.Text;
string Message = TextBox2.Text;
Jid ToUserJID = new Jid(ConstructJID(ToUser));
Jid FromUserJID = new Jid(ConstructJID(Username));
xmpp.Send(new Message(ToUserJID, MessageType.chat, Message));
Log.Text = Username + ": " + Message;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
xmpp = (XmppClientConnection)Cache["xmpp"];
if (xmpp == null)
{
xmpp = new XmppClientConnection();
Cache["xmpp"] = xmpp;
}
xmpp.MessageGrabber.Add(new Jid("vibhu@comp6"), new BareJidComparer(), new MessageCB(MessageCallBack), null);
}
protected void MessageCallBack(object sender, agsXMPP.protocol.client.Message msg, object data)
{
if (msg.Body == null)
{
return;
}
else
{
Chat.Text = msg.Body;
}
}
}
Forgive my spaghetti code, but any help at all would be useful.
First, I love the library you have built, and I wanted to let you know that we are building a Jabber/XMPP chat for our website of 4 million users using agsXMPP. (Is it the biggest implementation?) For the entire day today I've been trying to figure out why I can't get any messages to show up anywhere in the rapid prototype I'm making. I can login and logout and send a message. Ultimately, I want to long poll the received messages, but for now I'm happy just using a timed UpdatePanel so I can get a feel of sending and receiving. Here is my code:
//////////////////////Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="LoginButton" runat="server" Text="Login"
onclick="LoginButton_Click" />
<asp:Button ID="LogoutButton" runat="server" onclick="LogoutButton_Click"
Text="Logout" />
<br />
<br />
To:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
Message:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="SendMessage1" runat="server" Text="Send"
onclick="SendMessage1_Click" />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="GetMessages.aspx">Get New Messages</asp:HyperLink>
</div>
<asp:Label ID="Log" runat="server"></asp:Label>
<asp:Label ID="Log2" runat="server"></asp:Label>
<div id="chat">
</div>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Chat" runat="server" Text="Chat"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
////////////////////////Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using System.Threading;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private static XmppClientConnection xmpp;
string ConstructJID(string username)
{
string JID = username + "@comp6";
return JID;
}
public static string Username = "1";
public static string Password = "1";
protected void LoginButton_Click(object sender, EventArgs e)
{
xmpp = (XmppClientConnection)Cache["xmpp"];
if (xmpp == null)
{
xmpp = new XmppClientConnection();
Cache["xmpp"] = xmpp;
}
xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
xmpp.OnError += new ErrorHandler(xmpp_OnError);
xmpp.Port = 5222;
xmpp.UseSSL = false;
xmpp.Server = "comp6";
xmpp.Username = Username;
xmpp.Password = Password;
try
{
xmpp.Open();
Log.Text = "Logged in.";
}
catch (Exception ex)
{
Log.Text = ex.Message;
}
}
void xmpp_OnError(object sender, Exception ex)
{
}
void xmpp_OnLogin(object sender)
{
xmpp.SendMyPresence();
}
protected void LogoutButton_Click(object sender, EventArgs e)
{
XmppClientConnection xmpp = (XmppClientConnection)Cache["xmpp"];
try
{
xmpp.Close();
Cache.Remove("xmpp");
Log.Text = "Logged out.";
}
catch (Exception ex)
{
Log.Text = ex.Message;
}
}
protected void SendMessage1_Click(object sender, EventArgs e)
{
XmppClientConnection xmpp = (XmppClientConnection)Cache["xmpp"];
string ToUser = TextBox1.Text;
string Message = TextBox2.Text;
Jid ToUserJID = new Jid(ConstructJID(ToUser));
Jid FromUserJID = new Jid(ConstructJID(Username));
xmpp.Send(new Message(ToUserJID, MessageType.chat, Message));
Log.Text = Username + ": " + Message;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
xmpp = (XmppClientConnection)Cache["xmpp"];
if (xmpp == null)
{
xmpp = new XmppClientConnection();
Cache["xmpp"] = xmpp;
}
xmpp.MessageGrabber.Add(new Jid("vibhu@comp6"), new BareJidComparer(), new MessageCB(MessageCallBack), null);
}
protected void MessageCallBack(object sender, agsXMPP.protocol.client.Message msg, object data)
{
if (msg.Body == null)
{
return;
}
else
{
Chat.Text = msg.Body;
}
}
}
Forgive my spaghetti code, but any help at all would be useful.