Good C# XMPP Library supporting Group Chat and TLS or SSL Encryption [closed]

只谈情不闲聊 提交于 2019-12-03 09:19:53

Most of XmppClient works asynchronously. When you call someting like client.Open(), it returns immediately but you need to wait for it to raise the OnBind() event before doing anything with the mucManager. For example:

    public class ChatRoom
    {
        private readonly ILogger _logger;
        private XmppClient _client;
        private MucManager _mucManager;

        public ChatRoom(ILogger logger)
        {
            _logger = logger;           
        }

        public string UserName { get; set; }
        public string Password { get; set; }
        public string XmppDomain { get; set; }
        public System.Uri BoshUri { get; set; }
        public string RoomJid { get; set; }
        public string RoomNick { get; set; }

        public void Start()
        {
            _client = new XmppClient(UserName, XmppDomain, Password);               
            _client.OnBind += (o, e) => _CreateChatRoom(_client, RoomJid, RoomNick);
            _client.OnSendXml += (o, e) => Trace(ConsoleColor.DarkGreen, "Sending:\n {0}", e.Text);
            _client.OnReceiveXml += (o, e) => Trace(ConsoleColor.DarkMagenta, "Receiving:\n {0}", e.Text);
            _client.OnError += (o, e) => Trace(ConsoleColor.Red, "Error: {0}", e.Exception);
            _client.Open();
            _client.Close(); 
        }
        private void Trace(ConsoleColor color, string msg, params object[] args)
        {
            var oldColor = _logger.Color;
            _logger.Color = color;
            _logger.Log(msg, args);
            _logger.Color = oldColor;
            Debug.WriteLine(msg, args);
        }

        private void _CreateChatRoom(XmppClient client, string chatRoomName, string roomNick)
        {
            _mucManager = new MucManager(client);
            _mucManager.EnterRoom(chatRoomName, roomNick);            
        }

        public void SendMessage(string text)
        {
            _client.Send(new Message("muc@conference.dgwbhbm1", MessageType.groupchat, text));
        }

        public void End()
        {
            _client.Close();
        }

        public void Invite(Jid[] user)
        {
            _mucManager.Invite(user, RoomJid, "Come chat");
        }      
    }

So it looks as though all along that the answer to this question was that my original preferred library, (Soapbox Studio SDK) does in fact support TLS encryption and therefore was by best choice all along. It looks as though TLS is just not well documented and/or I missed this feature.

Depending upon your server configuration ( I am using an Openfire Server ), you should be able to configure your server to only accept encrypted connections. Rather than using the SSL (which Openfire is the process of deprecated from its server ) and attempting to connect over the SSL port 5223, Simply connected over the default port (5222) and requiring an encrypted connection will force the client to send the data using TLS and automatically negotiate the handshake. Also the server can be configured to prevent clients from creating additional users. By controlling which clients are able to create XMPP users on your server rather than issuing SSL certificates you therefore essentially ensure secure communication throughout.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!