문제

I have some code for XMPP messaging in C#. 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. sender@gmail.com is the full Jid

2) agsXMPP is completly asynchronous. Which means your xmpp.Open() call does not block. Your runs runs through and closes the connection immediately before it was established.

3) look at the agsXMPP examples

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top