Ejemplo n.º 1
0
        /// <summary>
        /// 上行(来自客户端的信息)
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(CustomSession session, CustomRequestInfo requestInfo)
        {
            string key = requestInfo.Key;

            Console.WriteLine($"[{command.GetDescription()}]命令被执行");
            Console.WriteLine("内容是:" + requestInfo.Body);

            string jsonData = "收到消息".GetTransmitPackets(command);

            session.Send(CustomCommand.TestCommand, jsonData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送命令和消息到服务器
        /// </summary>
        /// <param name="command"></param>
        /// <param name="message"></param>
        private void SendMessage(CustomCommand 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.WriteLog($"发送{command.GetDescription()}数据:" + message);

            DelegateAction(() =>
            {
                txtMsg.Text = string.Empty;
            });
        }