Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Same piece of codes and user credentials pass authentication in win form but fail in web app
Avatar
emperor #1
Member since Apr 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Authentication fails from web application
I want to implement a web chat based on XMPP & using ejabberd & agsXMPP. While trying to implement the login feature, always I am getting authentication failed. The same piece of code works in .net console & windows App. Any suggestions would be helpful.


Code Sample:
string JID_Sender = txtUserName.Text+"@MyPC";
        string Password = txtPassword.Text;

        Jid myJID = new Jid(txtUserName.Text + "@MyPC");
        jClient = new XmppClientConnection(myJID.Server);
        //jClient.OnReadXml += new XmlHandler(jClient_OnReadXml);
        //jClient.OnWriteXml += new XmlHandler(jClient_OnWriteXml);
        jClient.OnLogin += new ObjectHandler(jClient_OnLogin);
        //jClient.OnMessage += new agsXMPP.protocol.client.MessageHandler(jClient_OnMessage);
        jClient.OnError += new ErrorHandler(jClient_OnError);
        jClient.Server = "MyPC";
        //jClient.Resource = "test";
        jClient.Username = myJID.User;
        jClient.Password = txtPassword.Text;
        jClient.Status = "Online";
        jClient.Port = 5222;
        try
        {
            jClient.Open(myJID.User, txtPassword.Text);
            Response.Write("XmppConnectionState : " + jClient.XmppConnectionState.ToString());
            Response.Write("Authenticated status : " + jClient.Authenticated.ToString());
            //btnSend.Enabled = true;
            Response.Write("Login id : " + jClient.MyJID.ToString());
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
Avatar
Alex #2
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
there is no reason why it should fail in a web app. The code is doing exactly the same in web and console apps.
Did you try our basic webclient?

Alex
Avatar
emperor #3
Member since Apr 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
We had tried the web client also. But only a few times the authentication works. But most of the times it fails in the web app... whereas in the console & widows application the code works pretty well. Please find the ejabberd log for the reference.

LOG:

=INFO REPORT==== 2008-07-03 15:13:28 ===
I(<0.299.0>:mod_pubsub:152) : pubsub init "pc022862" [{access_createnode,
                                                       pubsub_createnode},
                                                      {plugins,
                                                       ["default","pep"]}]

=INFO REPORT==== 2008-07-03 15:13:28 ===
I(<0.299.0>:mod_pubsub:207) : ** tree plugin is nodetree_default

=INFO REPORT==== 2008-07-03 15:13:28 ===
I(<0.299.0>:mod_pubsub:211) : ** init default plugin

=INFO REPORT==== 2008-07-03 15:13:28 ===
I(<0.299.0>:mod_pubsub:211) : ** init pep plugin

=INFO REPORT==== 2008-07-03 15:13:34 ===
I(<0.262.0>:ejabberd_listener:112) : (#Port<0.367>) Accepted connection {{127,0,0,1},3014} -> {{127,0,0,1},5280}

=INFO REPORT==== 2008-07-03 15:13:35 ===
I(<0.255.0>:ejabberd_http:123) : started: {gen_tcp,#Port<0.367>}

=INFO REPORT==== 2008-07-03 15:13:36 ===
I(<0.262.0>:ejabberd_listener:112) : (#Port<0.372>) Accepted connection {{127,0,0,1},3015} -> {{127,0,0,1},5280}

=INFO REPORT==== 2008-07-03 15:13:36 ===
I(<0.255.0>:ejabberd_http:123) : started: {gen_tcp,#Port<0.372>}

=INFO REPORT==== 2008-07-03 15:13:38 ===
I(<0.262.0>:ejabberd_listener:112) : (#Port<0.373>) Accepted connection {{127,0,0,1},3016} -> {{127,0,0,1},5280}

=INFO REPORT==== 2008-07-03 15:13:38 ===
I(<0.255.0>:ejabberd_http:123) : started: {gen_tcp,#Port<0.373>}

=INFO REPORT==== 2008-07-03 15:14:19 ===
I(<0.260.0>:ejabberd_listener:112) : (#Port<0.374>) Accepted connection {{10,232,15,254},3022} -> {{10,232,15,254},5222}

=INFO REPORT==== 2008-07-03 15:14:30 ===
I(<0.260.0>:ejabberd_listener:112) : (#Port<0.381>) Accepted connection {{10,232,15,254},3024} -> {{10,232,15,254},5222}
Avatar
Alex #4
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
there are no errors in your ejabberd log.

I see no reason why the login should fail randomly with agsXMPP. It should either success or fail always with the same credentials and code. For me the basic webclient example succeeds always.

Alex
Avatar
Alex #5
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
please post you complete Xml Log from the console and the web application.

Alex
Avatar
emperor #6
Member since Apr 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Alex,

Now the code works fine. I m able to login & send message. While receiving the message, I got the message to my web app, but because the page is not rendering, I m unable to view the content in the UI. Is there any way to show the received content in the web UI.
Avatar
Alex #7
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

because this questions comes up very often I explain it again.

Web applications are normally poll only. This meas the client (webbrowser) is polling the webserver for new data when reloading the page. This can be done better with Ajax where the client in polling only for specific data and rerenders only parts of the webpage but not the whole webpage.

But "nomal" Ajax is still a poll mechanism, where the client requests info. What you need for a realtime enabled  application is the opposite where the client does not poll but the webserver is able to notify the client (webbrowser) of new events.

There are 2 ways to achieve this:
  • The client polls the webbrowser often (eg. every 30 seconds). The webapplication stores all incoming events on the server and delivers them to the client when it gets polled again. This technology is pretty easy to code but has disadvantages. Its not realtime, because the max. delay of the events equals the poll interval. And it increases the load and the traffic on your webserver with many unnecessary (empty) requests.
  • Use the technology called Comet. This technology is also know as Reverse Ajax, Ajax Push, Two-way-web and other. The Comet technology is described very well in the Wikipedia article (see link above). When possible you should choose the comet technology to deliver the agsXMPP events to your web UI.

I am willing to sponser the development of a comet enabled web chat example for agsXMPP. Experienced ASPX web developers who are interested to work on this can contact me over email at gnauck@ag-software.de or xmpp at gnauck@jabber.org.

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