/// <summary> /// 发送数据 /// </summary> /// <param name="cell">数据包对象</param> /// <param name="remoteIP">要发送到的目标网络节点</param> public void Send(SendCell cell, IPEndPoint remoteIP) { if (_started) { byte[] buffer = cell.ToBuffer(); SendInternal(buffer, remoteIP); } }
/// <summary> /// 从Byte数据获取数据包 /// </summary> /// <param name="buffer"></param> /// <returns></returns> public static SendCell FromBuffer(byte[] buffer) { try { SendCell sc = new SendCell(); sc._messageID = BitConverter.ToUInt16(buffer, 0); byte[] dataBuffer = new byte[buffer.Length - 2]; Buffer.BlockCopy(buffer, 2, dataBuffer, 0, buffer.Length - 2); sc._data = dataBuffer; return(sc); } catch (Exception) { return(null); } }