忱 沈 1 month ago
parent
commit
a470d9fa34
  1. 14
      AsyncTcpServer.cs

14
AsyncTcpServer.cs

@ -72,12 +72,14 @@ namespace ForwardingServer
} }
} }
else else
{
if (IsValidJson(DAT))
{ {
Personm deserializedPerson = JsonSerializer.Deserialize<Personm>(DAT)!; Personm deserializedPerson = JsonSerializer.Deserialize<Personm>(DAT)!;
DATA.MachineTable.Rows.Add(client.Id, client.IP, 30, "/" + deserializedPerson.SERVEREnterprise, DATA.MachineTable.Rows.Add(client.Id, client.IP, 30, "/" + deserializedPerson.SERVEREnterprise,
deserializedPerson.SERVERMachineName, deserializedPerson.MachineVer); deserializedPerson.SERVERMachineName, deserializedPerson.MachineVer);
Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss:fff") + " [LINK ID " + client.Id + " IP " + client.IP + "]\nDATA =" + DAT); Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss:fff") + " [LINK ID " + client.Id + " IP " + client.IP + "]\nDATA =" + DAT);
}
} }
} }
} }
@ -109,5 +111,15 @@ namespace ForwardingServer
Console.WriteLine("TcpServer:Run"); Console.WriteLine("TcpServer:Run");
} }
// 辅助方法检查JSON格式
private static bool IsValidJson(string jsonString)
{
if (string.IsNullOrEmpty(jsonString))
return false;
jsonString = jsonString.Trim();
return (jsonString.StartsWith("{") && jsonString.EndsWith("}")) ||
(jsonString.StartsWith("[") && jsonString.EndsWith("]"));
}
} }
} }

Loading…
Cancel
Save