【问题标题】:How to send ping packets using jabber-net library如何使用 jabber-net 库发送 ping 数据包
【发布时间】:2014-07-14 20:21:33
【问题描述】:

我正在开发一个 xmpp 客户端应用程序。我需要向 xmpp 服务器发送 ping iq 数据包,以确保服务器仍然存在。我如何通过 jabber-net 库发送它? 谢谢

【问题讨论】:

标签: c# xmpp openfire


【解决方案1】:

阅读FAQ_PacketsXEP-0199。将 NS 设置为 urn:xmpp:ping。比如:

namespace your.protocol
{
  public class PingQuery : Element
  {
    public const string PING_NS  = "urn:xmpp:ping";

    // used when creating elements to send
    public PingQuery(XmlDocument doc) : base("ping", PING_NS, doc)
    {}

    // used to create elements for inbound protocol
    public PingQuery(string prefix, XmlQualifiedName qname, XmlDocument doc)
        : base(prefix, qname, doc)
    {}
  }

  public class Factory : jabber.protocol.IPacketTypes
  {
    private static QnameType[] s_qnt = new QnameType[]
    {
      new QnameType("ping", PingQuery.PING_NS, typeof(your.protocol.PingQuery))
    };
    QnameType[] IPacketTypes.Types { get { return s_qnt; } }
  }
}

然后使用类似的东西:

private void jabberClient_OnStreamInit(object sender, ElementStream stream)
{
  stream.AddFactory(new your.protocol.Factory());
}

挂在你的工厂。然后像往常一样使用IQTracker 发送请求并获得响应通知。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多