Not able to connect agsXmpp client to eJabberd server

1.3k Views Asked by At

I am using Visual Studio 2010, and the OS is Windows 7, 64-bit. The project I am working on needs XMPP functionality in it; for this, I am using the agsXMPP library. The project type is a WPF client which throws up a window that stays there while my xmpp code is running.

I am running eJabberd 2.1.3 server on the same Windows system on which I am doing the development. I also created multiple accounts on the eJabberd server (like "aaa@mydomain", "bbb@mydomain", and so on) and "friended" them to each other.

For testing connectivity with my client, I am using Pandion Jabber client on Windows and a Xabber client on my Android on the same network. The setup is working fine and the Xabber and Pandion clients are able to exchange messages with each other. Just to ensure that there's no interference, I have temporarily disabled the Firewall.

Problem: I am unable to connect my program to the eJabberd server. The presence is just not shown on the other clients when the window is thrown up. I am using the following code:

    string uname = "aaa", domain_server = "mydomain", resource = "res1", password = "password";

    Jid jid = new Jid (uname, domain_server, resource);

    XmppClientConnection _xmppConn = new XmppClientConnection (jid.Server);

    // This is my development machine's IP address
    _xmppConn.ConnectServer = "192.168.0.101";

    _xmppConn.Server = domain_server;

    _xmppConn.Open (jid.User, password);

    // The event handlers:
    _xmppConn.OnLogin += new ObjectHandler (_xmppConn_OnLogin);
    _xmppConn.OnMessage += new agsXMPP.protocol.client.MessageHandler (_xmppConn_OnMessage);

    void _xmppConn_OnMessage (object sender, agsXMPP.protocol.client.Message msg) {
        MessageBox.Show (msg.Body);
    }

    void _xmppConn_OnLogin (object sender) {
        MessageBox.Show ("Logged in");
    }

The same code is working fine on Facebook chat, when I message the account from another FB account.

    string uname = "<my fb name>", domain_server = "facebook.com", resource = "res1", password = "<my password>";

    Jid jid = new Jid (uname, domain_server, resource);

    XmppClientConnection _xmppConn = new XmppClientConnection (jid.Server);

    _xmppConn.Server = "chat.facebook.com";

    _xmppConn.Open (jid.User, password);

    // The event handlers:
    _xmppConn.OnLogin += new ObjectHandler (_xmppConn_OnLogin);
    _xmppConn.OnMessage += new agsXMPP.protocol.client.MessageHandler (_xmppConn_OnMessage);

    void _xmppConn_OnMessage (object sender, agsXMPP.protocol.client.Message msg) {
        MessageBox.Show (msg.Body);
    }

    void _xmppConn_OnLogin (object sender) {
        MessageBox.Show ("Logged in");
    }

I have been racking my brains but am just not able to figure out where I may be going wrong. Can somebody please help? Thank you in advance. :)

3

There are 3 best solutions below

0
On BEST ANSWER

I think I figured it out. Since I was on a development system working with a "custom" domain, that is, mydomain, and not a well-known TLD resolved via the public DNS, I had to add an entry to the hosts file located here:

C:\Windows\System32\drivers\etc\hosts

Added the following entry (assuming 192.168.0.101 as your dev system's IP address):

192.168.0.101 mydomain

And comment out or delete this line in the code:

_xmppConn.ConnectServer = "192.168.0.101";

This will enable the library to figure out the address of "mydomain" to the IP address specified in the hosts file above on your local development machine.

Edit: Also make sure that you disable IPV6 on your system. See this thread: http://forum.ag-software.net/thread/682-agsXMPP-SDK-1-0-samples-How-to-call-server-on-loc

Instructions on how to disable IPV6: http://www.techunboxed.com/2014/10/how-to-disable-ipv6-in-windows-10.html

0
On

I think - based on some very light testing - that ConnectServer expects a hostname and throws an error if you give it an IP address.

1
On

The ConnectServer property gets ignored until you disable the automatic SRV resolving with

xmppCon.AutoResolveConnectServer = false;

This should solve your problem.