.NET的XMPP開發包 JabberNet

webphp 12年前發布 | 24K 次閱讀 XMPP 網絡工具包

JabberNet 是一個 .NET 的 Jabber (XMPP)協議的客戶端開發包,示例代碼:

using System;
using System.Threading;

using jabber.client;

namespace SendMessage { class Program { // we will wait on this event until we're done sending static ManualResetEvent done = new ManualResetEvent(false); // if true, output protocol trace to stdout const bool VERBOSE = true; const string TARGET = "otheruser@example.com";

    static void Main(string[] args)
    {
        JabberClient j = new JabberClient();
        // what user/pass to log in as
        j.User = "someuser";
        j.Server = "example.com";  // use gmail.com for GoogleTalk
        j.Password = "somepassword";

        // don't do extra stuff, please.
        j.AutoPresence = false;
        j.AutoRoster = false;
        j.AutoReconnect = -1;

        // listen for errors.  Always do this!
        j.OnError += new bedrock.ExceptionHandler(j_OnError);

        // what to do when login completes
        j.OnAuthenticate += new bedrock.ObjectHandler(j_OnAuthenticate);

        // listen for XMPP wire protocol
        if (VERBOSE)
        {
            j.OnReadText += new bedrock.TextHandler(j_OnReadText);
            j.OnWriteText += new bedrock.TextHandler(j_OnWriteText);
        }

        // Set everything in motion
        j.Connect();

        // wait until sending a message is complete
        done.WaitOne();

        // logout cleanly
        j.Close();
    }

    static void j_OnWriteText(object sender, string txt)
    {
        if (txt == " ") return;  // ignore keep-alive spaces
        Console.WriteLine("SEND: " + txt);
    }

    static void j_OnReadText(object sender, string txt)
    {
        if (txt == " ") return;  // ignore keep-alive spaces
        Console.WriteLine("RECV: " + txt);
    }

    static void j_OnAuthenticate(object sender)
    {
        // Sender is always the JabberClient.
        JabberClient j = (JabberClient)sender;
        j.Message(TARGET, "test");

        // Finished sending.  Shut down.
        done.Set();
    }

    static void j_OnError(object sender, Exception ex)
    {
        // There was an error!
        Console.WriteLine("Error: " + ex.ToString());

        // Shut down.
        done.Set();
    }
}

}</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1326030758500

 本文由用戶 webphp 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!