/// <summary> /// 发送广播消息 /// </summary> /// <param name="cmd">消息命令字类型</param> public void BoardCast(wawCMD cmd) { List <byte> bytesource = new List <byte>(); if ((cmd == wawCMD.WAW_BC_ABSENCE) || (cmd == wawCMD.WAW_BC_BUSY) || (cmd == wawCMD.WAW_BC_CHECKNEWVER) || (cmd == wawCMD.WAW_BC_GETLIST) || (cmd == wawCMD.WAW_BC_SIGNIN) || (cmd == wawCMD.WAW_BC_SIGNOUT)) { bytesource.AddRange(PreDefine.DataHeadPreProcess(cmd)); byte[] sendbuff = bytesource.ToArray(); udpclient.Send(sendbuff, sendbuff.Length, boardcast_ipport); } }
/// <summary> /// /// </summary> /// <param name="ipendpoint"></param> /// <param name="txt">要发送的消息文本</param> public MsgSend(IPEndPoint ipendpoint, wawCMD cmd, string txt) { remote_ipport = ipendpoint; List <byte> bytesource = new List <byte>(); bytesource.AddRange(PreDefine.DataHeadPreProcess(cmd)); bytesource.AddRange(Encoding.UTF8.GetBytes(txt)); sendbuff = bytesource.ToArray(); //也可使用如下方法进行byte数组拼接,一般来讲,对于大byte数组,采用泛型效率要高很多 //byte[] sendbuf = PreDefine.DataHeadPreProcess(cmd).Concat(Encoding.UTF8.GetBytes(txt)).ToArray(); }