简体   繁体   English

我如何在C#中将agsxmpp用于gtalk配置?

[英]How can i use agsxmpp for gtalk configure in c#?

I have some code for XMPP messaging in C#. 我在C#中有一些用于XMPP消息传递的代码。 I am not able to send a message to another user. 我无法向其他用户发送消息。

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;
        }
    }
}

What am I doing wrong? 我究竟做错了什么?

1) username is sender (lowercase), not Sender@gmail.com . 1)用户名是发件人 (小写),而不是Sender@gmail.com sender@gmail.com is the full Jid sender@gmail.com是完整的Jid

2) agsXMPP is completly asynchronous. 2)agsXMPP是完全异步的。 Which means your xmpp.Open() call does not block. 这意味着您的xmpp.Open()调用不会被阻止。 Your runs runs through and closes the connection immediately before it was established. 运行将在连接建立之前立即运行并关闭该连接。

3) look at the agsXMPP examples 3)看agsXMPP示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM