zoukankan      html  css  js  c++  java
  • JabberNet -Jabbber .net客户端框架(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();
            }
        }
    }
    
  • 相关阅读:
    云服务器Ubuntu更改默认python版本
    例题4-1-3-古老的密码、刽子手的游戏,救济金发放
    Github pages和Hexo搭建自己的博客
    Python字典基本操作介绍
    python win32api win32gui win32con PyUserInput实现自动化脚本
    spring--分类索引
    目录-java并发基础知识
    【转】集群单点故障的应对策略
    CnBlogs自定义博客样式
    读书笔记——《redis入门指南(第2版)》第七章 持久化
  • 原文地址:https://www.cnblogs.com/l1pe1/p/14706904.html
Copyright © 2011-2022 走看看