我将以下代码放在我正在编写的 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,尼洛