我在C#中有一些XMPP消息传递的代码。我无法向其他用户发送消息。
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using System.Threading;
using Microsoft.Win32;
public partial class Talk : Form
{
agsXMPP.XmppClientConnection objXmpp;
public Talk()
{
InitializeComponent();
}
private void btnSend_Click(object sender, EventArgs e)
{
XmppClientConnection xmpp = new XmppClientConnection();
xmpp.Server = "gmail.com";
xmpp.ConnectServer = "talk.google.com";
xmpp.Port = 5222;
xmpp.Username = "Sender@gmail.com";
xmpp.Password = "******";
xmpp.Open();
agsXMPP.Jid JID = new Jid("receiver@gmail.com");
xmpp.MesagageGrabber.Add(JID, new agsXMPP.Collections.BareJidComparer(), new MessageCB(MessageCallBack), null);
agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
msg.Type = agsXMPP.protocol.client.MessageType.chat;
msg.To = JID;
msg.Body = " asdfasdfasdf " ;// simple string
xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); };
xmpp.Close();
}
static void MessageCallBack(object sender,agsXMPP.protocol.client.Message msg,object data)
{
if (msg.Body != null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("{0}>> {1}", msg.From.User, msg.Body);
Console.ForegroundColor = ConsoleColor.Green;
}
}
}
我做错了什么?
答案 0 :(得分:1)
1)用户名为发件人(小写),而不是 Sender@gmail.com 。 sender@gmail.com是完整的Jid
2)agsXMPP是完全异步的。这意味着您的xmpp.Open()调用不会阻止。您的运行会在建立之前立即运行并关闭连接。
3)查看agsXMPP示例