Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
s0h0 #1
Member since Dec 2007 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: onlogin event feuert nicht?
hallo,

da ich im live support auf deutsch hilfe bekam, schreib ich hier au mal auf deutsch.
ich möchte einen simplen webchat client schreiben. die komponenten liegen alle in einem ajax update panel...

msg senden geht wenn ich es wie in der doku mache...

ich lese jetzt die xmppcon wenns kein postback ist aus der session aus. aber trotzdem wird der onlogin event nicht gefeuert ( selbes problem mit MessageCB)...
irgendwas entscheidendes fehlt noch, evtl ein javascript page refresh?

ich hoffe jemand kann mir helfen! :o

hier mal mein code:

    XmppClientConnection xmpp;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            set_session_xmpp();
            if (Session.Count > 0)
            {
                xmpp = (XmppClientConnection)Session["xmpp_con"];
            }
        }
        else
        {
            xmpp = (XmppClientConnection)Session["xmpp_con"];
        }
       
        string JID_Sender = "lean5";
        string JID_Receiver = "s0h0@jabber.shrimps.homelinux.net";
        string Password = "58369";
        Jid jidSender = new Jid(JID_Sender);


        xmpp.Open(jidSender.User, Password);
        xmpp.OnLogin += new agsXMPP.ObjectHandler(xmpp_OnLogin);
       // xmpp.MesagageGrabber.Add(new Jid(JID_Receiver), new BareJidComparer(), new MessageCB(MessageCallBack), null);
        Literal1.Text += "Versuche zu verbinden...";
    }

    protected void xmpp_OnLogin(object sender)
    {
        try
        {
            xmpp.Send(new Message("s0h0@jabber.shrimps.homelinux.net", MessageType.chat, TextBox1.Text));
        }
        catch (Exception eg)
        {
            Literal1.Text += "<br>FEHLER:" + eg.ToString();
        }
        Literal1.Text += "<br>Logged in";
    }




    protected void MessageCallBack(object sender, agsXMPP.protocol.client.Message msg, object data)
    {
        Literal1.Text += msg.From.User + msg.Body;  
    }


 protected void set_session_xmpp()
    {
        try
        {
            XmppClientConnection xmpp = new XmppClientConnection("jabber.shrimps.homelinux.net");
            Session.Add("xmpp_con", xmpp);
        }
        catch (Exception egl0)
        {
            Literal1.Text += "<br>FEHLER:" + egl0.ToString();
        }
    }
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
This forum is english only! Please post in english in the future.

the following code works for us without any problems. The Login event gets fired.

Global.asax.cs
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Web;
  5. using System.Web.SessionState;
  6.  
  7. using agsXMPP;
  8.  
  9. namespace webclient
  10. {   
  11.     public class Global : System.Web.HttpApplication
  12.     {
  13.         private System.ComponentModel.IContainer components = null;
  14.  
  15.         public Global()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private XmppClientConnection xmpp;
  21.        
  22.         protected void Application_Start(Object sender, EventArgs e)
  23.         {
  24.             xmpp = new XmppClientConnection();
  25.             Application["xmpp"] = xmpp;
  26.  
  27.             xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
  28.         }
  29.  
  30.         void xmpp_OnLogin(object sender)
  31.         {
  32.             // OnLogin gets fired here
  33.         }
  34.  
  35.         protected void Session_Start(Object sender, EventArgs e)
  36.         {
  37.  
  38.         }
  39.  
  40.         protected void Application_BeginRequest(Object sender, EventArgs e)
  41.         {
  42.  
  43.         }
  44.  
  45.         protected void Application_EndRequest(Object sender, EventArgs e)
  46.         {
  47.  
  48.         }
  49.  
  50.         protected void Application_AuthenticateRequest(Object sender, EventArgs e)
  51.         {
  52.  
  53.         }
  54.  
  55.         protected void Application_Error(Object sender, EventArgs e)
  56.         {
  57.  
  58.         }
  59.  
  60.         protected void Session_End(Object sender, EventArgs e)
  61.         {
  62.  
  63.         }
  64.  
  65.         protected void Application_End(Object sender, EventArgs e)
  66.         {
  67.  
  68.         }
  69.            
  70.        
  71.         private void InitializeComponent()
  72.         {   
  73.             this.components = new System.ComponentModel.Container();
  74.         }
  75.        
  76.     }
  77. }

WebForm.aspx

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. using agsXMPP;
  13.  
  14. namespace webclient
  15. {
  16.    
  17.     public partial class WebForm1 : System.Web.UI.Page
  18.     {   
  19.         protected void Page_Load(object sender, System.EventArgs e)
  20.         {                    
  21.         }
  22.  
  23.    
  24.         override protected void OnInit(EventArgs e)
  25.         {   
  26.             InitializeComponent();
  27.             base.OnInit(e);
  28.         }
  29.        
  30.         private void InitializeComponent()
  31.         {   
  32.  
  33.         }
  34.        
  35.         protected void btnLogin_Click(object sender, System.EventArgs e)
  36.         {
  37.            
  38.             XmppClientConnection xmpp;
  39.            
  40.             xmpp = (XmppClientConnection)Application["xmpp"];
  41.          
  42.             xmpp.OnLogin        += new ObjectHandler(xmpp_OnLogin);
  43.            
  44.             xmpp.Port = 5222;
  45.             xmpp.UseSSL=false;
  46.             xmpp.Server = "jabber.org";
  47.             xmpp.Username = "username";
  48.             xmpp.Password = "password";   
  49.  
  50.             xmpp.Open();
  51.            
  52.         }
  53.  
  54.         protected void btnLogout_Click(object sender, System.EventArgs e)
  55.         {
  56.             XmppClientConnection xmpp;
  57.  
  58.             xmpp = (XmppClientConnection)Application["xmpp"];
  59.             xmpp.Close();
  60.         }
  61.  
  62.         private void xmpp_OnLogin(object sender)
  63.         {
  64.             // Onlogin gets also fired here
  65.             txtDebug.Text += "we are logged in to the server now";
  66.             XmppClientConnection xmpp;
  67.             xmpp = (XmppClientConnection)Application["xmpp"];
  68.             xmpp.SendMyPresence();
  69.         }
  70.        
  71.     }
  72. }
Avatar
s0h0 #3
Member since Dec 2007 · 6 posts
Group memberships: Members
Show profile · Link to this post
hello,

thank you for your answear.

i tried to copy your sample but im using .net 2.0 and i dont have a Global.asax.cs... just a Global.asax.
i fixed it with <%@ Import Namespace="agsXMPP"%> inside the Global.asax


but it still keep saying try to connect and dont fire the loginEvent

can this be othe problem?
The events OnMessage, OnLogin etc... get raised by agsXMPP which runs on the server. This means if you get this events while debugging they are on the webserver, not on the client. And you can't update the clients GUI without reloading the page or other techniques like temporary polling or reverse AJAX.


Do you have a solution for this problem?



Meine Global.asax

<%@ Application Language="C#" %>
<%@ Import Namespace="agsXMPP"%>

<script runat="server">
   

       
        private System.ComponentModel.IContainer components = null;
 
        public void Global()
        {
          
            InitializeComponent();
        }
 
        private XmppClientConnection xmpp;
       
        protected void Application_Start(Object sender, EventArgs e)
        {
            xmpp = new XmppClientConnection();
            Application["xmpp"] = xmpp;
 
            xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
        }
 
        void xmpp_OnLogin(object sender)
        {
            XmppClientConnection xmpp;
            xmpp = (XmppClientConnection)Application["xmpp"];
            xmpp.SendMyPresence();
        }
 
        protected void Session_Start(Object sender, EventArgs e)
        {
 
        }
 
        protected void Application_BeginRequest(Object sender, EventArgs e)
        {
 
        }
 
        protected void Application_EndRequest(Object sender, EventArgs e)
        {
 
        }
 
        protected void Application_AuthenticateRequest(Object sender, EventArgs e)
        {
 
        }
 
        protected void Application_Error(Object sender, EventArgs e)
        {


        }
 
        protected void Session_End(Object sender, EventArgs e)
        {
 
        }
 
        protected void Application_End(Object sender, EventArgs e)
        {
 
        }
           
       
        private void InitializeComponent()
        {   
            this.components = new System.ComponentModel.Container();
        }

      
</script>


Meine Default.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using agsXMPP;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
        override protected void OnInit(EventArgs e)
        {  
            InitializeComponent();
            base.OnInit(e);
        }
       
        private void InitializeComponent()
        {   
 
        }
       
        protected void btnLogin_Click(object sender, System.EventArgs e)
        {

            txtDebug.Text += "Versuche zu verbinden...";
            XmppClientConnection xmpp;
           
            xmpp = (XmppClientConnection)Application["xmpp"];
         
            xmpp.OnLogin        += new ObjectHandler(xmpp_OnLogin);
           
            xmpp.Port = 5222;
            xmpp.UseSSL=false;
            xmpp.Server = "jabber.shrimps.lobo.net";
            xmpp.Username = "un";
            xmpp.Password = "pw";  
 
            xmpp.Open();
           
        }
 
        protected void btnLogout_Click(object sender, System.EventArgs e)
        {
            XmppClientConnection xmpp;
 
            xmpp = (XmppClientConnection)Application["xmpp"];
            xmpp.Close();
        }
 
        private void xmpp_OnLogin(object sender)
        {
            // Onlogin gets also fired here
            txtDebug.Text += "we are logged in to the server now";
            XmppClientConnection xmpp;
            xmpp = (XmppClientConnection)Application["xmpp"];
            xmpp.SendMyPresence();
        }

   
}
This post was edited 3 times, last on 2007-12-18, 11:55 by s0h0.
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The do it with a webform only. This works for us too.
We are no ASPX professionals, so we can't help you a lot with ASPX. Only with all agsXMPP and web technology related questions.


WebForm.aspx

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. using agsXMPP;
  13.  
  14. namespace webclient
  15. {   
  16.     public partial class WebForm1 : System.Web.UI.Page
  17.     {   
  18.         XmppClientConnection xmpp;
  19.  
  20.         protected void Page_Load(object sender, System.EventArgs e)
  21.         {                    
  22.         }
  23.    
  24.         override protected void OnInit(EventArgs e)
  25.         {   
  26.             InitializeComponent();
  27.             base.OnInit(e);
  28.         }
  29.        
  30.         private void InitializeComponent()
  31.         {   
  32.  
  33.         }
  34.        
  35.  
  36.         protected void btnLogin_Click(object sender, System.EventArgs e)
  37.         {         
  38.             xmpp = (XmppClientConnection)Application["xmpp"];
  39.             if (xmpp == null)
  40.             {
  41.                 xmpp = new XmppClientConnection();
  42.                 Application["xmpp"] = xmpp;
  43.             }  
  44.          
  45.             xmpp.OnLogin        += new ObjectHandler(xmpp_OnLogin);
  46.            
  47.             xmpp.Port = 5222;
  48.             xmpp.UseSSL=false;
  49.             xmpp.Server = "jabber.org";
  50.             xmpp.Username = "username";
  51.             xmpp.Password = "password";   
  52.  
  53.             xmpp.Open();           
  54.         }
  55.  
  56.         protected void btnLogout_Click(object sender, System.EventArgs e)
  57.         {
  58.             XmppClientConnection xmpp;
  59.  
  60.             xmpp = (XmppClientConnection)Application["xmpp"];
  61.             xmpp.Close();
  62.         }
  63.  
  64.         private void xmpp_OnLogin(object sender)
  65.         {
  66.             // Onlogin gets also fired here
  67.             txtDebug.Text += "we are logged in to the server now";
  68.             XmppClientConnection xmpp;
  69.             xmpp = (XmppClientConnection)Application["xmpp"];
  70.             xmpp.SendMyPresence();
  71.         }      
  72.     }
  73. }
Avatar
s0h0 #5
Member since Dec 2007 · 6 posts
Group memberships: Members
Show profile · Link to this post
ok, i did what u said. but the onlogin event still dont get fired.

u know some possible causes for that?

maybe its a problem with the jabber server?
some settings he dont send me a login response or something like that?

thank u
Avatar
s0h0 #6
Member since Dec 2007 · 6 posts
Group memberships: Members
Show profile · Link to this post
thats my current code:


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
using agsXMPP;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    override protected void OnInit(EventArgs e)
    {
        InitializeComponent();
        base.OnInit(e);
    }

    private void InitializeComponent()
    {

    }

    protected void btnLogin_Click(object sender, System.EventArgs e)
    {
        Response.Write("versuche zu verbinden");
        txtDebug.Text += "Versuche zu verbinden...";
        XmppClientConnection xmpp;

        xmpp = (XmppClientConnection)Application["xmpp"];

        xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);

        xmpp.Port = 5222;
        xmpp.UseSSL = false;
        xmpp.Server = "jabber.shrimps.homelinux.net";
        xmpp.Username = "un";
        xmpp.Password = "pw";

        xmpp.Open();
        xmpp.AutoAgents = true;
        Response.Write(xmpp.Authenticated);
      //  Thread.Sleep(500);
    }

    protected void btnLogout_Click(object sender, System.EventArgs e)
    {
        XmppClientConnection xmpp;

        xmpp = (XmppClientConnection)Application["xmpp"];
        xmpp.Close();
    }

    private void xmpp_OnLogin(object sender)
    {
        Response.Write("login");
        try
        {
            // Onlogin gets also fired here
            txtDebug.Text += "we are logged in to the server now";
            XmppClientConnection xmpp;
            xmpp = (XmppClientConnection)Application["xmpp"];
           // xmpp.Send("hallo");
            xmpp.SendMyPresence();
        }
        catch(Exception e)
        {
            txtDebug.Text += e.ToString();
          
        }

    }


}
This post was edited on 2007-12-28, 14:45 by s0h0.
Avatar
Alex #7
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
did you try the code I posted before?
I don't see where you create a new instance of XmppClientConnection in your code.
You always retrieve it from the session, but never create it and store it in the session. This cannot work.

Correct me if I'm wrong.

Alex
Avatar
s0h0 #8
Member since Dec 2007 · 6 posts
Group memberships: Members
Show profile · Link to this post
hello,

thank u for ur reply


i think i just changed one detail of ur code.
now i copyed it 1to1 and just added few debug messages...

but it still wont work. i really dont want to bore u but i cant get it working.


here is my current code of the Default.aspx.cs:

Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;

using agsXMPP;

public partial class _Default : System.Web.UI.Page
{
    XmppClientConnection xmpp;

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    override protected void OnInit(EventArgs e)
    {
        InitializeComponent();
        base.OnInit(e);
        txtDebug.Text += "<br>oninit<br>" + e.ToString();
    }

    private void InitializeComponent()
    {
    }


    protected void btnLogin_Click(object sender, System.EventArgs e)
    {
        if (xmpp != null)
        {
            txtDebug.Text += "<br>" + xmpp.MyJID;
            txtDebug.Text += "<br>" + xmpp.Status;
        }

        txtDebug.Text += "<br>try to connect";
        try
        {
            xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);

            xmpp.Port = 5222;
            xmpp.UseSSL = false;
            xmpp.Server = "jabber.shrimps.homelinux.net";
            xmpp.Username = "leyer";
            xmpp.Password = "leyer";

            xmpp.Open();
        }
        catch (Exception ela)
        {
            txtDebug.Text += "<br>ERROR:" + ela.ToString();
        }
    }

    protected void btnLogout_Click(object sender, System.EventArgs e)
    {
        XmppClientConnection xmpp;

        xmpp = (XmppClientConnection)Application["xmpp"];
        xmpp.Close();
    }

    private void xmpp_OnLogin(object sender)
    {
        // Onlogin gets also fired here
        txtDebug.Text += "<br>we are logged in to the server now";
       // XmppClientConnection xmpp;
        xmpp = (XmppClientConnection)Application["xmpp"];
        xmpp.SendMyPresence();
    }
}
Avatar
Alex #9
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you still don't create a new XmppClientConnection object.

  1. XmppClientConnection xmpp = new XmppClientConnection()
Avatar
s0h0 #10
Member since Dec 2007 · 6 posts
Group memberships: Members
Show profile · Link to this post
i thought that will happen here:
where should i insert it?

protected void btnLogin_Click(object sender, System.EventArgs e)
    {

        xmpp = (XmppClientConnection)Application["xmpp"];
        if (xmpp == null)
        {
            xmpp = new XmppClientConnection();
            Application["xmpp"] = xmpp;
        } 

        if (xmpp != null)
        {



but i got now that im connected to the server and just dont get resaponse on clientside.
that should be fixed with ajax but an ajax updatepanel.refresh in the onlogin event wont work
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