c# - “agsXMPP.MessageGrabber”是 'type',但使用方式类似于 'variable'

标签 c#

代码如下:

  XmppClientConnection xmpp = new XmppClientConnection();
        xmpp.Server = "gmail.com";
        xmpp.ConnectServer = "talk.google.com";
        xmpp.Username = "aleksandr.gordon";
        xmpp.Password = "password";
        xmpp.Open();

        agsXMPP.Jid JID = new Jid("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbafb3bebcbab9b6beb2a8afbea9ea9bbcb6bab2b7f5b8b4b6" rel="noreferrer noopener nofollow">[email protected]</a>");
        xmpp.MessageGrabber.Add(JID, new agsXMPP.Collections.BareJidComparer(), new MessageCB(xmpp.MessageGrabber), null);

        agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
        msg.Type = agsXMPP.protocol.client.MessageType.chat;
        msg.To = JID;
        msg.Body = "how u doing" + DateTime.Now.ToString();

        xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); };

更新了新代码:

    agsXMPP.Jid JID = new Jid("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ce8f4f9fbfdfef1f9f5efe8f9eedcfbf1fdf5f0b2fff3f1" rel="noreferrer noopener nofollow">[email protected]</a>");
    xmpp.MessageGrabber.Add(JID, new agsXMPP.Collections.BareJidComparer(),
        new MessageCB(delegate(object sender, agsXMPP.protocol.client.Message msg, object data)
    {
    }), null);
    agsXMPP.protocol.client.Message msg1 = new agsXMPP.protocol.client.Message();
    msg1.Type = agsXMPP.protocol.client.MessageType.chat;
    msg1.To = JID;
    msg1.Body = "how u doing" + DateTime.Now.ToString();

    xmpp.OnLogin += delegate(object o) { xmpp.Send(msg1); };

我做错了什么?为什么我会收到此错误?

最佳答案

您可能需要传递委托(delegate)方法,请尝试将此方法添加到您的代码中

void Login() {
    XmppClientConnection xmpp = new XmppClientConnection();
    xmpp.Server = "gmail.com";
    xmpp.ConnectServer = "talk.google.com";
    xmpp.Username = "aleksandr.gordon";
    xmpp.Password = "password";
    xmpp.Open();

    agsXMPP.Jid JID = new Jid("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65110d0002040708000c1611001754250208040c094b060a08" rel="noreferrer noopener nofollow">[email protected]</a>");
    xmpp.MessageGrabber.Add(JID, new agsXMPP.Collections.BareJidComparer(), new MessageCB(GrabMessage), null);

    agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
    msg.Type = agsXMPP.protocol.client.MessageType.chat;
    msg.To = JID;
    msg.Body = "how u doing" + DateTime.Now.ToString();

    xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); };
}

protected void GrabMessage(object sender, agsXMPP.protocol.client.Message msg, object data) {
}

这是我能建议的最后一件事,但上述方法有效并且可以解决您的问题,除非您在其他地方遇到其他问题:

xmpp.MessageGrabber.Add(JID, new agsXMPP.Collections.BareJidComparer(),
    new MessageCB(delegate(object sender, agsXMPP.protocol.client.Message msg, object data) {
    if (msg.Body != null) {
        MessageBox.Show(msg.Body);
    }
    }), null);

关于c# - “agsXMPP.MessageGrabber”是 'type',但使用方式类似于 'variable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3073022/

相关文章:

c# - 如何使用 Asp.Net 4.7 和带有 Microsoft.Extensions.DependencyInjection 的 DI 设置 Hangfire?

c# - 使用代码验证 Microsoft Dynamics CRM

c# - 不使用属性将对象序列化为 XML

c# - 如何在 Windows 10 创意者更新中正确使用 Acrylic Accent (CreateHostBackDropBrush())?

c# - 添加自定义 httpmodule 以选择性地路由到 MVC 或自定义处理程序

c# - Lambda 表达式 LINQ 等同于 SQL Exists Query on Same Table/Variable

c# - Azure存储1.7 : how to make a simple select that works everytime?

c# - 根据c#中的客户端分辨率调整网页大小

c# mysql datetime 到 unix 时间

c# - join 子句中的表达式之一的类型不正确