2014-08-27 217 views
0

我使用的是Visual Studio 2010,操作系统是Windows 7,64位。我正在进行的项目需要XMPP功能;为此,我正在使用agsXMPP库。项目类型是一个WPF客户端,它在我的xmpp代码正在运行时引发一个停留在那里的窗口。无法将agsXmpp客户端连接到eJabberd服务器

我在同一个Windows系统上运行eJabberd 2.1.3服务器,我在其中进行开发。我还在eJabberd服务器上创建了多个帐户(例如“aaa @ mydomain”,“bbb @ mydomain”等等)并将它们“融洽”在一起。

为了测试与客户端的连接性,我在Windows上使用Pandion Jabber客户端,在同一网络上使用Android上的Xabber客户端。设置工作正常,Xabber和Pandion客户端可以相互交换消息。为了确保没有干扰,我暂时禁用了防火墙。

问题:我无法将我的程序连接到eJabberd服务器。当窗口被抛出时,在其他客户端上不显示该状态。我使用下面的代码:

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"); 
    } 

相同的代码在Facebook上聊工作正常,当我的消息从另一个FB帐户的帐户。

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"); 
    } 

我一直在绞尽脑汁,但只是无法弄清楚我可能会出错的地方。有人可以帮忙吗?先谢谢你。 :)

+0

我不知道很多关于agsxmpp,但也许你需要登录后手动发送的存在? – legoscia 2014-08-27 14:51:48

+0

@legoscia,我尝试添加这一行:_xmppConn.AutoPresence = TRUE;在代码中。不要去那里。 – Najeeb 2014-08-27 14:55:05

+0

'telnet 192.168.0.101 5222'是否工作? – vitalyster 2014-08-27 18:14:37

回答

0

我想我想通了。由于我使用的是一个使用“自定义”域的开发系统,即mydomain,而不是通过公共DNS解析的着名TLD,因此我必须向位于此处的hosts文件添加条目:

C:\ WINDOWS \ SYSTEM32 \ DRIVERS \等\主机

添加以下条目(假设192.168.0.101作为dev系统的IP地址):

192.168.0.101 MYDOMAIN

,并注释掉或在代码中删除此行:

_xmppConn.ConnectServer =“192.168.0.101”;

这将使库能够将本地开发计算机上的hosts文件中指定的IP地址“mydomain”的地址计算出来。

编辑:另外请确保您在您的系统上禁用IPV6。请参阅本主题:如何禁用IPv6 http://forum.ag-software.net/thread/682-agsXMPP-SDK-1-0-samples-How-to-call-server-on-loc

说明:http://www.techunboxed.com/2014/10/how-to-disable-ipv6-in-windows-10.html

0

,直到您禁用自动SRV与

xmppCon.AutoResolveConnectServer = false; 

此解决应该解决您的问题ConnectServer的属性,都会被忽略。

+0

我希望我能说你的解决方案比我的解决方案更好,因为我觉得修改代码而不是适应环境总是有意义的。我试过这个(我之前也做过),但不幸的是它不起作用。 :(无论如何感谢您的回复。 – Najeeb 2014-09-04 03:18:21

0

我认为 - 基于一些非常轻的测试 - ConnectServer预计主机名并在给它一个IP地址时引发错误。