static void updateConfig() { List <NodeDes> NodeDesList = NodeDes.importData(); strNodesDes = JsonConvert.SerializeObject(NodeDesList); NodeInfoParser.UpdateNodeDic(NodeDesList); Console.WriteLine("节点信息已更新:"); Console.WriteLine(strNodesDes); }
static void StartWebSocketServer(int _websocketPort) { string url = "ws://localhost:" + _websocketPort.ToString(); WebSocketServer server = new WebSocketServer(url); server.Start(socket => { string originurl = socket.ConnectionInfo.Host + socket.ConnectionInfo.Path; socket.OnOpen = () => { Console.WriteLine(originurl + " connected"); if (socket.ConnectionInfo.Path == "/Client") { addClient(socket, ClientList); Debug.WriteLine("Client ++ => " + ClientList.Count.ToString()); } command c = new command("nodeDes", strNodesDes); socket.Send(JsonConvert.SerializeObject(c) as string); }; socket.OnClose = () => { Console.WriteLine(originurl + " closed"); removeClient(socket, ClientList); }; socket.OnMessage = message => { Debug.WriteLine("OnMessage => " + message); //List<TagInfo> tags = TagPool.GetAllExistsTags(); //string json = JsonConvert.SerializeObject(tags); //socket.Send(json); if (message == "nodeDes") { command c = new command("nodeDes", strNodesDes); socket.Send(JsonConvert.SerializeObject(c) as string); } if (message == "nodes") { command c = new command("nodes", NodeInfoParser.GetNodesJson()); socket.Send(JsonConvert.SerializeObject(c) as string); //socket.Send(NodeInfoParser.GetNodesJson()); } }; socket.OnError = (error) => { Debug.WriteLine("OnError => " + error.Data); removeClient(socket, ClientList); }; }); }
static void timerActOnInputData_Elapsed(object sender, ElapsedEventArgs e) { if (sbuilderInputData.Length > 0) { string temp = sbuilderInputData.ToString(); int lastIndex = temp.LastIndexOf("</MotePacket>"); if (lastIndex > 0) { int length = lastIndex + 13; string complete = temp.Substring(0, length); sbuilderInputData.Remove(0, length); NodeInfoParser.UpdateNodeInfo(complete); #if DEBUG Debug.WriteLine("********************************"); Debug.WriteLine(complete.Replace("\0", "")); Debug.WriteLine("********************************"); #endif } Debug.WriteLine(sbuilderInputData.ToString().Replace("\0", "")); } }