/// <summary> /// 发送命令和消息到服务器 /// </summary> /// <param name="command"></param> /// <param name="message"></param> public static void SendMessage(StentSignalEnum command, string message) { if (client == null || !client.IsConnected || message.Length <= 0) { return; } var response = BitConverter.GetBytes((ushort)command).Reverse().ToList(); var arr = System.Text.Encoding.UTF8.GetBytes(message); response.AddRange(BitConverter.GetBytes((ushort)arr.Length).Reverse().ToArray()); response.AddRange(arr); client.Send(response.ToArray()); LogHelper.Log.Info($"发送{command.GetDescription()}数据:" + message + " byte:" + BitConverter.ToString(response.ToArray())); }
public static void SendMessage(StentSignalEnum command, byte[] message) { if (client == null || !client.IsConnected) { return; } var response = BitConverter.GetBytes((ushort)command).Reverse().ToList(); if (message.Length > 0) { response.AddRange(BitConverter.GetBytes((ushort)message.Length).Reverse().ToArray()); response.AddRange(message); } client.Send(response.ToArray()); LogHelper.Log.Info($"发送{command.GetDescription()}数据:" + message + " byte:" + BitConverter.ToString(response.ToArray())); }