Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
narendra1 #1
Member since Jan 2011 · 1 post
Group memberships: Members
Show profile · Link to this post
Subject: Need Start UP to develope Web-Chat
Hello,

We are trying to develop a web client-server chat using agsXMPP.
We had write some code for creating a xmpp connection and sending chat message to particular client...
the work we have done is as follows....
//////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using agsXMPP;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using System.Threading;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;


namespace WebClient
{
    public partial class _Default : System.Web.UI.Page
    {

        private XmppClientConnection xmpp;
        private ArrayList messages;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack && !IsCallback)
            {
                xmpp = (XmppClientConnection)Cache["xmpp"];
                if (xmpp == null)
                {
                    xmpp = new XmppClientConnection();
                    Cache["xmpp"] = xmpp;
                }
                xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);

             
               
                xmpp.AutoResolveConnectServer = true;

                xmpp.Port = 5222;
                xmpp.UseSSL = false;

                xmpp.Server = "jwchat.org";
                xmpp.Username = "narendra1";
                xmpp.Password = "abcd";

                xmpp.Open();

                xmpp.OnMessage += new MessageHandler(xmpp_OnMessage);

                messages = new ArrayList();
                Cache["messages"] = messages;
            }


          }

    void xmpp_OnMessage(object sender, Message msg)
        {
            ArrayList messages = Cache["messages"] as ArrayList;
            messages.Add(msg.Body);
        }

        void xmpp_OnLogin(object sender)
        {
     
            xmpp.Send(new Message(new Jid("yashaswi@jwchat.org"), MessageType.chat, "Hello, how are you?"));
        }

        protected void cmdLogout_Click(object sender, EventArgs e)
        {
            xmpp = (XmppClientConnection)Cache["xmpp"];
            xmpp.Close();
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            txtConversation.Text = txtConversation.Text + "\n" + "me: " + txtNewText.Text;
            xmpp.Send(new Message(new Jid("yashaswi@jwchat.org"), MessageType.chat, txtNewText.Text));
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            ArrayList messages = Cache["messages"] as ArrayList;
            if (messages != null)
            {
                if (messages.Count > 0)
                {
                    foreach (string message in messages)
                    {
                        txtConversation.Text = txtConversation.Text + "\n" + "me: " + message;
                    }
                }
                messages.Clear();
            }
        }

    [System.Web.Services.WebMethod]
        public static void SendMessage(string uniqueID, string text)
        {
            XmppClientConnection xmpp = (XmppClientConnection)HttpRuntime.Cache["xmpp"];
            xmpp.Send(new Message(new Jid("yashaswi@jwchat.org"), MessageType.chat, "Hi Hi"));
        }
       
//////////////////////////////////////////////////////////////////////////////////////////



The above code doesn't give me a error but the message does not deliver to receiver......
So, anybody can help me to correct the problem......
Avatar
Alex #2
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
did you try to set a breakpoint on the OnMessage handler to see if the messages come in?
Can you subscribe to the OnReadXml and OnWriteXml handlers to the the XMPP debug Xml?

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS