private DataPackt GetBindAck(byte[] buffer) { DataPackt packet = new DataPackt(); MemoryStream ms = new MemoryStream(buffer, false); BinaryReader br = new BinaryReader(ms); packet.Name = ExtendedTrim(Encoding.UTF8.GetString(br.ReadBytes(20))); packet.Subject = ExtendedTrim(Encoding.UTF8.GetString(br.ReadBytes(20))); packet.Grade = IPAddress.NetworkToHostOrder(br.ReadInt32()); packet.Memo = ExtendedTrim(Encoding.UTF8.GetString(br.ReadBytes(100))); br.Close(); ms.Close(); return(packet); }
private void clientThread(object sender) { TcpClient client = sender as TcpClient; NetworkStream stream = client.GetStream(); byte[] buffer = new byte[8092]; DataPackt packet = new DataPackt(); while (stream.Read(buffer, 0, buffer.Length) != 0) { packet = GetBindAck(buffer); } stream.Close(); client.Close(); string Name = packet.Name; string Subject = packet.Subject; Int32 Grade = packet.Grade; string Memo = packet.Memo; Debug.WriteLine("{0} : {1} : {2} : {3}", Name, Subject, Grade, Memo); Invoke((MethodInvoker) delegate { int count = listView1.Items.Count; count++; ListViewItem i = new ListViewItem(); i.Text = count.ToString(); i.SubItems.Add(Name); i.SubItems.Add(Subject); i.SubItems.Add(Grade.ToString()); i.SubItems.Add(Memo); i.SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); listView1.Items.Add(i); listView1.Items[this.listView1.Items.Count - 1].EnsureVisible(); }); updateStatusInfo("Data Accepted"); }