我已将以下代码放在我正在编写的Jabbernet客户端上:
private void Roster_OnRosterEnd(object sender)
{
QueryUser(new JID("lixo@icts.br"));
QueryUser(new JID("abc@icts.br"));
QueryUser(new JID("nilo@icts.br"));
QueryUser(new JID("simone@icts.br"));
}
private void QueryUser(JID jid)
{
IQ search = new IQ(Client.Document);
search.From = Client.User.ToString() + "@" + Client.Server.ToString();
search.To = "search." + Client.Server.ToString();
search.ID = "search2";
search.Type = IQType.set;
search.InnerXml = "<query xmlns='jabber:iq:search'><nick>" + jid.User + "</nick></query>";
Client.Tracker.BeginIQ(search, new jabber.connection.IqCB(OnSearch), jid);
}
private void OnSearch(object sender, IQ iq, object data)
{
Error err = iq.Error;
if (err != null)
Console.WriteLine("Error " + err.Condition + " on querying user " + data);
if (iq.Query.ChildNodes.Count == 0)
{
Console.WriteLine("No answer querying user " + data);
}
foreach (Element a in iq.Query)
{
Console.WriteLine("Answer querying user: " + data + " --> " + a.OuterXml);
}
}
问题是:方法OnSearch只执行一次,无论我尝试多少次搜索。我想对于我发送的每次搜索都会执行一次该方法...
我错过了什么?
更新
只是为了澄清......我试图发现用户是否存在,如果是,我可以发送邀请,具体取决于将收到邀请的用户的VCard中包含的字段的内容并决定如果邀请可以发送或不。
TIA, 尼罗
答案 0 :(得分:2)
为每个请求使用不同的ID。您的错误就在这一行:
search.ID = "search2";
保留一个计数器,或者只允许IQ构造函数为您生成一个。另外,不要费心设置起始地址:
search.From = Client.User.ToString() + "@" + Client.Server.ToString();
删除这两行,它应该有效。