这是代码:
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("thegabmeister1@gmail.com");
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("thegabmeister@gmail.com");
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); };
我错了什么?为什么我会收到此错误?
答案 0 :(得分:2)
您可能需要传递委托方法,尝试将此方法添加到您的代码
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("thegabmeister1@gmail.com");
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);
答案 1 :(得分:1)
new MessageCB(MessageGrabber)
应该是:
new MessageCB(xmpp.MessageGrabber)
至于你做错了什么,你使用的类型agsXMPP.MessageGrabber
就像一个变量,它不会编译。