I am using Jabber-Net library ( JabberNet-2.1.0.710.msi downloaded from http://code.google.com/p/jabber-net/downloads/list ) and OpenFire 3.6.4 downloaded from here.
I use the jabber-net with visual studio and I have a problem.
When I want to add a new contact to my roster, I get an infinite of subscribe presence’s from the server.
I let the OnPresence be handled default by the Jabber-Net lib, I do not register a callback. (but when I register it I see the packets).
When I use jabberd server it works fine.
It is very easy to reproduce the bug (I think it is a bug)
If you download the sources of JabberNet they have an example of application made using JabberNet lib (i put compiled app in attachament, this is just how my app add a new contact).
I open Example, connect to server with user1, then I use Spark and connect with user2.
When I add from Example-app user2 to user1’s roster, after I click accept in spark (to accept the subscription), Example-app keeps on getting presence subscribe requests from server, and my processor is 100% busy.
I really want to use OpenFire server for my app, but this kind of overhead is unnacceptable.
How should this be handles.
As I see from the sources this is how OnPresence method is handled by default in the Jabber-Net lib:
Tell me if there is something wrong with it, or tell if there is something I should do to configure Openfire to work
Thanks.
private void cli_OnPresence(object sender, Presence pres)
{
PresenceType typ = pres.Type;
switch (typ)
{
case PresenceType.available:
case PresenceType.unavailable:
case PresenceType.error:
case PresenceType.probe:
return; //doesn’t matter with these
case PresenceType.subscribe:
switch (m_autoAllow)
{
case AutoSubscriptionHanding.AllowAll:
ReplyAllow(pres);
return;
case AutoSubscriptionHanding.DenyAll:
ReplyDeny(pres);
return;
case AutoSubscriptionHanding.NONE:
if (OnSubscription != null)
OnSubscription(this, this[pres.From], pres);
return;
case AutoSubscriptionHanding.AllowIfSubscribed:
Item ri = this[pres.From];
if (ri != null)
{
switch (ri.Subscription)
{
case Subscription.to:
ReplyAllow(pres);
return;
case Subscription.from:
case Subscription.both:
// Almost an assert
throw new InvalidOperationException(“Server sent a presence subscribe for an already-subscribed contact”);
case Subscription.none:
if (ri.Ask == Ask.subscribe)
{
ReplyAllow(pres);
return;
}
break;
}
}
if (OnSubscription != null)
OnSubscription(this, ri, pres);
break;
}
break;
case PresenceType.subscribed:
// This is the new ack case.
Presence sub_ack = new Presence(m_stream.Document);
sub_ack.To = pres.From;
sub_ack.Type = PresenceType.subscribe;
m_stream.Write(sub_ack);
break;
case PresenceType.unsubscribe:
// ack. we’ll likely get an unsubscribed soon, anyway.
Presence un_ack = new Presence(m_stream.Document);
un_ack.To = pres.From;
un_ack.Type = PresenceType.unsubscribed;
m_stream.Write(un_ack);
break;
case PresenceType.unsubscribed:
bool remove = true;
if (OnUnsubscription != null)
OnUnsubscription(this, pres, ref remove);
if (remove)
Remove(pres.From);
break;
}
}