public void UniCast(XmppSeverConnection contexCon, FoxundermoonLib.XmppEx.Data.Message message) { Message msg = new Message(); if (null == message.FromUser) { msg.From = ServerJid; } else { msg.From = getJidFromUser(message.FromUser); } if (null != message.ToUser) { msg.To = getJidFromUser(message.ToUser); } msg.Language = "BASE64"; msg.Subject = message.GetJsonCommand(); msg.Body = FoxundermoonLib.Encrypt.EncryptUtil.EncryptBASE64ByGzip(message.ToJson()); try { contexCon.Send(msg); } catch (Exception e) { Console.WriteLine("*****@*****.**" + e.Message); } }
public void Broadcast2resource(FoxundermoonLib.XmppEx.Data.Message message, string resource) { Message msg = new Message(); if (null == message.FromUser) { msg.From = getJidFromUser(message.FromUser); } else { msg.From = getJidFromUser(message.FromUser); } msg.Body = FoxundermoonLib.Encrypt.EncryptUtil.EncryptBASE64ByGzip(message.ToJson()); msg.Subject = message.GetJsonCommand(); msg.Language = "BASE64"; foreach (var cons in XmppConnectionDic) { XmppSeverConnection con = null; var hasCon = cons.Value.TryGetValue(resource, out con); if (hasCon) { Jid to = new Jid(cons.Key + "@" + Config.ServerIp + "/" + resource); msg.To = to; try { con.Send(msg); } catch (Exception e) { Console.WriteLine("[email protected] message:" + e.Message); } } } }
//处理客户端与服务器的通信 在此处加入服务器相关业务逻辑代码 private void HandleServerMsg(XmppSeverConnection con, Message msg) { if (msg.Body == "123456") { Message m = new Message(); m.Body = "-----------------------"; m.From = new Jid("1@localhost"); m.To = msg.From; con.Send(m); } }