void Bind_Data() //ListBox绑定数据显示 { try { List <information> List_User = new List <information>(); information l_LAVE = new information(); while (true) { string[] tokens = wp_hx_Client.Re_List().Split(new Char[] { '|' }); if (tokens[0] == "Client") { try { List_User = (List <information>)FromJson(tokens[1]); } catch (Exception e) { MessageBox.Show(e.Message); } foreach (information p in List_User) { //MessageBox.Show("用户登录"+p.name + " " + p.ip); NowIp.Append(p.name + "$" + p.ip + "|"); } List_User.Clear(); } else if (tokens[0] == "Quit") { try { l_LAVE = (information)FromJson_leave(tokens[1]); //MessageBox.Show("用户退出" + l_LAVE.name + " " + l_LAVE.ip); Debug.WriteLine("用户退出" + l_LAVE.name + " " + l_LAVE.ip, DateTime.Now.ToLongTimeString()); string nowAll = NowIp.ToString(); string[] item = nowAll.Split('|'); NowIp.Length = 0; for (int i = 0; i < item.Length - 1; i++) { string[] p = item[i].Split('$'); if (p[1] != l_LAVE.ip) { NowIp.Append(item[i] + "|"); } } } catch (Exception e) { Debug.WriteLine(e.Message, DateTime.Now.ToLongTimeString()); } List_User.Clear(); //List_Documents.ItemsSource = Ip_Item;//指定ListBox的数据来源为的数组 } } } catch (Exception e) { } }
public information FromJson_leave(string json) { information jsonObject = null; try { var ser = new DataContractJsonSerializer(typeof(information)); using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json))) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(information)); jsonObject = (information)jsonSerializer.ReadObject(ms); } } catch (Exception e) { } return(jsonObject); }