title: How to send and receive List using Tcp NetworkStream C#
body: <p>I just started learning socket programming and now I`m trying to send List&lt;> from Client to Server. </p>
  
  <p>I`ve read that i need to Serialize and Deserialize using BinaryFormatter but i just didnt know how to send it to server using NetworkStream. </p>
  
  <p>Please help and any explanation will be very much appreciated. Thank you very much in advanced.</p>
  
  <p>Below is my code for Client</p>
  
  <pre><code>private void btnSendDataToServer_Click(object sender, EventArgs e)
      {
          int noOfMessage = Convert.ToInt32(tbMessageNo.Text);
          try
          {
              serverStream = clientSocket.GetStream();
              for (int i = 0; i &lt; noOfMessage; i++)
              {
                  clientList.Add(tbSendDataToServer.Text);
              }
  
              //send data to server
              byte[] outStream = System.Text.Encoding.ASCII.GetBytes(?); 
              serverStream.Write(outStream, 0, outStream.Length);
              serverStream.Flush();
  
              //receive data from server
              byte[] inStream = new byte[102400]; 
              serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
              string returndata = System.Text.Encoding.ASCII.GetString(inStream); 
              msg("Data from Server : " + returndata);
          }
          catch(SocketException ex)
          { }
      }
  </code></pre>
  
  <p>Below is my code for Server</p>
  
  <pre><code>byte[] bytesFrom = new byte[102400];
  
  NetworkStream networkStream = clientSocket.GetStream();
                  networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                  dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
  
                      f.testQS.Enqueue(dataFromClient);
                      AppendText(f.testQS.Count().ToString() + " &gt;&gt; " + "From client-" + ClientNo + "--" + dataFromClient);
  
                      //send data to client
                      rCount = Convert.ToString(requestCount);
                      serverResponse = "Server to Client(" + ClientNo + ") " + rCount;
                      sendBytes = Encoding.ASCII.GetBytes(serverResponse);
                      networkStream.Write(sendBytes, 0, sendBytes.Length);
                      networkStream.Flush();
  </code></pre>
  
  <p>P.s. If it is a single string, i have no problem doing it. But i want to loop the string 1st based on the user noOfMessage and put it in List. Then i will send the List to Server. Then, the Server will read List received and display the data of the List. Thank you.</p>