Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
trw1313 #1
Member since Oct 2009 · 10 posts
Group memberships: Members
Show profile · Link to this post
Subject: Login to EJabberd Issue
I have an eJabberd server running with 3 users (admin configured) and rosters created for each.

I have a small winform app (c#) attempting to login into the server using the agsXMPP libs.  I have basically
cut and pasted the code from the console app sample in the SDK.  The OnLogin event never fires which
means I think that I am not logged in. 

Also, the server seems never to have gotten the Logon message......at least no log messages are written.  Also,
I have had the server running in "Live" mode and nothing was written to the console.

For my test, the client application is running on the same machine as xmpp server.

Also, I tried just running the consoleclient app and the same behaviour was seen.

I am assuming port 5222 is the working port since this is C2S connection.  The listener on the server
is setup to be port 5222.  I've tried assigning the port and not assigning it with the same results.

I see the open() call is a return of void which tells me I don't really know what the status of my open/login
attempt is.

Any help would be greatly appreciated....thanks

TRW
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the lib is async. Therefor catch the OnLogin and OnError events after the Open call.
Please post your Xml log for diagnostics.

Alex
Avatar
trw1313 #3
Member since Oct 2009 · 10 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex:

Yes, I am catching the OnLogin in which I display some logging.  The callback function is never
returned.  I did not implement the OnError callback.  I will try that to see if that is called.

How do I get the XML Log diagnostics?

My apologies, this is my first time using this product.

Many thanks!

TRW
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by trw1313:
How do I get the XML Log diagnostics?

Subscribe to the OnReadXml and OnWriteXml handlers.
Also attach your source when possible.
Avatar
trw1313 #5
Member since Oct 2009 · 10 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex:

I added the event handlers for read and write XML to the test console application.  No event
was triggered for the Open() call.   I then attempted to send a message (should not work)
and I get the following on the console.

Enter you Jid (user@server.com):
admin@testhost
Enter password for 'admin@testhost':
PassworD1
Wait
You are logged in to the server now.

Available commands are:
msg toJid text
status show{online, away, xa, chat} status
help
quit

Examples:
msg test@server.com Hello World
msg test@server.com/Office Hello World
status chat free for chat

msg test1@testhost hello
SEND XML: <message to="test1@testhost" type="chat"><body>hello</body></messag
e>
quit
SEND XML: </stream:stream>
Press any key to continue . . .

That's it....My user is NOT registered with the server.  I checked that and no message was received by the server.

Here is the code I have used (left out the misc functions)

namespace ConsoleClient
{
    class Program
    {
        static bool _bWait;
       
        static void Main(string[] args)
        {
            XmppClientConnection xmppCon = new XmppClientConnection();

            Console.Title = "Console Client";
            // read the jid from the console
            PrintHelp("Enter you Jid (user@server.com): ");
            Jid jid = new Jid(Console.ReadLine());

            PrintHelp(String.Format("Enter password for '{0}': ", jid.ToString()));

            xmppCon.Password = Console.ReadLine();
           
            xmppCon.Username = jid.User;
            xmppCon.Server = jid.Server;
            xmppCon.AutoAgents = false;
            xmppCon.AutoPresence = true;
            xmppCon.AutoRoster = true;
            xmppCon.UseSSL = false;

            // Connect to the server now
            // !!! this is asynchronous !!!
            try
            {
                 xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
                xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
                xmppCon.OnError += new ErrorHandler(xmppCon_OnError);
                xmppCon.OnWriteXml += new XmlHandler(xmppCon_OnWriteXml);
                xmppCon.OnReadXml += new XmlHandler(xmppCon_OnReadXml);

                // Open Connection
                xmppCon.Open("admin", "PassworD1");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Wait("Login to server, please wait");
            PrintCommands();

            bool bQuit = false;

            while (!bQuit)
            {
                string command = Console.ReadLine();
                string[] commands = command.Split(' ');

                switch (commands[0].ToLower())
                {
                    case "help":
                        PrintCommands();
                        break;
                    case "quit":
                        bQuit = true;
                        break;
                    case "msg":
                        string msg = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Send(new Message(new Jid(commands[1]), MessageType.chat, msg));
                        break;
                    case "status":
                        switch (commands[1])
                        {
                            case "online":
                                xmppCon.Show = ShowType.NONE;
                                break;
                            case "away":
                                xmppCon.Show = ShowType.away;
                                break;
                            case "xa":
                                xmppCon.Show = ShowType.xa;
                                break;
                            case "chat":
                                xmppCon.Show = ShowType.chat;
                                break;
                        }
                        string status = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Status = status;
                        xmppCon.SendMyPresence();
                        break;
                }
            }

            // close connection
            xmppCon.Close();
        }
        private static void Wait(string statusMessage)
        {
            int i = 0;
            _bWait = true;
            Console.WriteLine("Wait");
            while (_bWait)
            {
                i++;
                if (i == 60)
                    _bWait = false;

                Thread.Sleep(500);
            }

           
        }

        static void xmppCon_OnLogin(object sender)
        {
            Console.WriteLine("OnLogin!!!!!");
            Console.WriteLine();
            PrintEvent("Logged in to server");
        }

  
        static void xmppCon_OnMessage(object sender, Message msg)
        {

            if (msg.Body != null)
            {
                PrintEvent(String.Format("Got message from: {0}", msg.From.ToString()));
                PrintEvent("message: " + msg.Body);
                PrintInfo("");
            }
        }

        static void xmppCon_OnError(object sender,
                                    Exception ex)
        {
            Console.WriteLine("Error!!!!" + ex.Message.ToString());
        }

        static void xmppCon_OnWriteXml(object sender, string xml)
        {
 
            Console.WriteLine("SEND XML: " + xml);
        }

        static void xmppCon_OnReadXml(object sender, string xml)
        {
            Console.WriteLine("REC XML: " + xml);
        }

 }
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by trw1313:
My user is NOT registered with the server.  I checked that and no message was received by the server.

can you please elaborate on this? What do you mean with "...NOT registered with the server".

  • Have you tried the examples I provide with the SDK? Do they work?
  • Are your 2 test users subscribed to each other correctly?
  • In your code I can't see you sending your presence. If a user has not sent a presence to the server it receives no messages.

Alex
Avatar
trw1313 #7
Member since Oct 2009 · 10 posts
Group memberships: Members
Show profile · Link to this post
Thanks again Alex.

My users ARE registered with the eJabberd server for the specified host.

I run the following command:

C:\Program Files\ejabberd\bin>ejabberdctl registered_users testhost
admin
test1
test2

I meant to say/imply (sorry, I am new to the verbage)  the connected users is empty.
I guess this command should tell me if a user/client has logged in.  If I run the
following command after the connection I would expect to see "admin" or whatever
user got logged in....The command result is empty is what I meant to say.


C:\Program Files\ejabberd\bin>ejabberdctl connected_users testhost

No I can not get any of the SDK examples to work.  The code I copied from above was
at one point the consoleclient sample that I have been playing with.

Yes, I believe the users are subscribed correctly in the server.  All 3 of my users have the
same credentials and are in each other rosters.

What do you mean by "sending a presence"?  I had the following event handler defined and
the delegate added to the xmppconnection object

       static void xmppCon_OnPresence(object sender, Presence pres)
        {
            PrintInfo(String.Format("Got presence from: {0}", pres.From.ToString()));
            PrintInfo(String.Format("type: {0}", pres.Type.ToString()));
            PrintInfo(String.Format("status: {0}", pres.Status));
            PrintInfo("");
        }

Am I missing something?

Also, I noticed the IPV6 issue in some other threads.  This could be the problem since I am running on Vista with
IPV6 addressing is being used.

I really can't change the O/S at the moment to IPV4 so I would have to do that in my ejabberd configuration.

Thanks again for help and any advice you may have for me!

TRW
Avatar
Alex #8
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
if your code hits the OnLogin handler then you connected successfully.
Try to execute a status command first before you send a message. Then your server should show you as online.

Alex
Avatar
trw1313 #9
Member since Oct 2009 · 10 posts
Group memberships: Members
Show profile · Link to this post
Alex, I never hit the OnLogin on any attempt.....the program just hangs until the wait() finishes.

I've bumped up the time in the wait method with no luck.

Here are some results from running the status.  I am not sure what I'm looking for
in the logs.  I have the ejabberd server running in "live" mode which displays messages
when it receives something.  I don't get anything displayed tothe console of the server.

Available commands are:
msg toJid text
status show{online, away, xa, chat} status
help
quit

Examples:
msg test@server.com Hello World
msg test@server.com/Office Hello World
status chat free for chat

status show chat status
SEND XML: <presence><status>chat status</status><priority>5</priority></presence
>
status chat free for chat
SEND XML: <presence><show>chat</show><status>free for chat</status><priority>5</
priority></presence>
Avatar
Alex #10
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
can you check if a socket is established by using a sniffer like wireshark?
If not then it may be the V4/V6 issue like discussed here several times before.

By default ejabberd is using V4 only, and your OS may resolve the domain testhost to a V6 address. This will not work. You have either to enable v6 on ejabberd, or modify your hosts file or dns server to return a v4 address.

Alex
Avatar
trw1313 #11
Member since Oct 2009 · 10 posts
Group memberships: Members
Show profile · Link to this post
I will investigate.

At the moment, I am having issues configuring eJabberd to have port 5222 use IPV6.

I have done what he guide suggests however, when I start the server up it tells me
the inet6 option is not valid.....I've opened a thread up on their forum regarding this.

Have you worked with that before or not?   Probably a stupid question, but I figured
maybe you have dealt with that before.

Much appreciated!!

TRW
Avatar
Alex #12
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by trw1313:
the inet6 option is not valid.....I've opened a thread up on their forum regarding this.

Have you worked with that before or not?   Probably a stupid question, but I figured
maybe you have dealt with that before.

no, for testing I install ejabberd in LAN, VmWare or on the local developer machine. To overcome the V6 problems I specify a v4 address my hosts file for the domain used for ejabberd. This could be any valid domain.

Alex
Avatar
trw1313 #13
Member since Oct 2009 · 10 posts
Group memberships: Members
Show profile · Link to this post
Subject: Fixed!
Thanks Alex

It was the IPv6 issue.  I added the domain to my hosts file with ipv4 and restarted the server.

Everything worked fine after that....awesome!!

Thanks again!!

TRW
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