title: send complex object using socket in C# but also simple text string
body: <p>my goal is to send simple text data and also complex data to client application using socket..this is some of my code</p>
  
  <pre><code> private void button1_Click(object sender, EventArgs e)
   {
  
          byte[] data;
          data = Encoding.ASCII.GetBytes("Welcome!!!");
          ns.Write(data, 0, data.Length);
          ns.Flush();
  
          List&lt;Person&gt; list = new List&lt;Person&gt;();
          for (int a = 0; a &lt; 5; a++)
          {
              Person person = new Person();
              person.Name = textBox1.Text;
              person.Age = int.Parse(textBox2.Text);
              list.Add(person);
          }
  
          BinaryFormatter formatter = new BinaryFormatter();
          for (int a = 0; a &lt; 5; a++)
          {
              formatter.Serialize(ns, list[a]);
          }
          ns.Flush();
   }
  </code></pre>
  
  <p>and at the client i write this code to add all data to listview</p>
  
  <pre><code> private void AddToListView()
   {
           while (true &amp;&amp; ns.DataAvailable)
           {
              byte[] data = new byte[1024];
              int recv;
              recv = ns.Read(data, 0, data.Length);
              textFromServer = Encoding.ASCII.GetString(data, 0, recv);
              ns.Flush();
              listView1.Items.Add(textFromServer);
  
              temp = formatter.Deserialize(ns) as Person;
              ns.Flush();
              listView1.Items.Add(temp.Name);
              listView1.Items.Add(temp.Age);
          }
      }
  </code></pre>
  
  <p>but when i debug the application,,nothing happens...if i delete the networkstream read() process,,the application run nicely..the problem is,i not only need to send the user object,,but also simple text to client..can someone help me please?</p>
  
  <p>is it possible using networkstream.read() and binaryformatter.deserialize() at the same time??or,we have to choose one of it?</p>
  
  <p>i mean when just to send/receive simple text,,we use networkstream.read()/write(),,and for complex object we use serialize/deserialize..is it possible??</p>