我使用的是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");
}
我一直在绞尽脑汁,但只是无法弄清楚我可能会出错的地方。有人可以帮忙吗?先谢谢你。 :)
我不知道很多关于agsxmpp,但也许你需要登录后手动发送的存在? – legoscia 2014-08-27 14:51:48
@legoscia,我尝试添加这一行:_xmppConn.AutoPresence = TRUE;在代码中。不要去那里。 – Najeeb 2014-08-27 14:55:05
'telnet 192.168.0.101 5222'是否工作? – vitalyster 2014-08-27 18:14:37