public string GetClientsInfoJson() { var connectionManager = ClientConnectionManager.GetInstance(); StringBuilder json = new StringBuilder("[ "); foreach (var(key, value) in ServerContext.PortAppMap) { if (value.Count > 0) { foreach (var(key2, value2) in value) { AddAppJsonItem(json, key, value2); } } else { AddAppJsonItem(json, key, value.ActivateApp); } } foreach (var(key, value) in ServerContext.UDPPortAppMap) { if (value.Count > 0) { foreach (var(key2, value2) in value) { AddAppJsonItem(json, key, value2); } } else { AddAppJsonItem(json, key, value.ActivateApp); } } json.D(); json.Append("]"); return(json.ToString()); }
public string GetClientsInfoJson() { var connectionManager = ClientConnectionManager.GetInstance(); StringBuilder json = new StringBuilder("[ "); foreach (var(key, value) in ServerContext.PortAppMap) { json.Append("{ "); json.Append(KV2Json("port", key)).C(); json.Append(KV2Json("clientId", value.ClientId)).C(); json.Append(KV2Json("appId", value.AppId)).C(); json.Append(KV2Json("blocksCount", value.TcpClientBlocks.Count)).C(); //反向连接 json.Append(KV2Json("revconns")); json.Append("[ "); foreach (var reverseClient in value.ReverseClients) { json.Append("{ "); if (reverseClient.Connected) { json.Append(KV2Json("lEndPoint", reverseClient.Client.LocalEndPoint.ToString())).C(); json.Append(KV2Json("rEndPoint", reverseClient.Client.RemoteEndPoint.ToString())); } json.Append("}"); json.C(); } json.D(); json.Append("]").C(); //隧道状态 json.Append(KV2Json("tunnels")); json.Append("[ "); foreach (var tunnel in value.Tunnels) { json.Append("{ "); if (tunnel.ClientServerClient != null) { Socket sktClient = tunnel.ClientServerClient.Client; if (tunnel.ClientServerClient.Connected) { json.Append(KV2Json("clientServerClient", $"{sktClient.LocalEndPoint}-{sktClient.RemoteEndPoint}")) .C(); } } if (tunnel.ConsumerClient != null) { Socket sktConsumer = tunnel.ConsumerClient.Client; if (tunnel.ConsumerClient.Connected) { json.Append(KV2Json("consumerClient", $"{sktConsumer.LocalEndPoint}-{sktConsumer.RemoteEndPoint}")) .C(); } } json.D(); json.Append("}"); json.C(); } json.D(); json.Append("]"); json.Append("}").C(); } json.D(); json.Append("]"); return(json.ToString()); }