我使用的是 Visual Studio 2010,操作系统是 Windows 7,64 位。我正在从事的项目需要 XMPP 功能;为此,我正在使用 agsXMPP 库。项目类型是一个 WPF 客户端,它会在我的 xmpp 代码运行时抛出一个窗口。
我在进行开发的同一 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");
}
当我从另一个 FB 帐户向该帐户发送消息时,相同的代码在 Facebook 聊天中运行良好。
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");
}
我一直在绞尽脑汁,但就是无法弄清楚我哪里可能出错了。有人可以帮忙吗?先感谢您。:)