wanshenmean
13 小时以前 c9a1df9c19a64844d05d120ff171f523d77e7823
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SocketServer/TcpSocketServer.Messaging.cs
@@ -2,6 +2,7 @@
using System.Text;
using System.Text.Json;
using System.IO;
using WIDESEAWCS_Model.Models;
namespace WIDESEAWCS_Tasks.SocketServer
{
@@ -22,8 +23,7 @@
        /// <param name="client">TCP 客户端连接</param>
        /// <param name="clientId">客户端唯一标识</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <param name="robotCrane">机器人状态</param>
        public async Task HandleClientAsync(TcpClient client, string clientId, CancellationToken cancellationToken, RobotSocketState robotCrane)
        public async Task HandleClientAsync(TcpClient client, string clientId, CancellationToken cancellationToken)
        {
            using (client)
            using (NetworkStream networkStream = client.GetStream())
@@ -59,10 +59,14 @@
                            break;
                        }
                        if(message == lastMessage)
                        // 按客户端去重:检查是否与该客户端上次消息相同
                        lock (_syncRoot)
                        {
                            // 重复消息,忽略
                            continue;
                            if (_clientLastMessage.TryGetValue(clientId, out var prev) && message == prev)
                            {
                                continue;
                            }
                            _clientLastMessage[clientId] = message;
                        }
                        // 更新客户端状态
@@ -83,7 +87,7 @@
                            {
                                // 判断是否为 JSON 格式
                                bool isJsonFormat = TryParseJsonSilent(message);
                                _ = MessageReceived.Invoke(message, isJsonFormat, client, robotCrane);
                                _ = MessageReceived.Invoke(message, isJsonFormat, client);
                            }
                            catch { }
                        }