title: NetworkStream.Flush() in C# Socket programming
body: <p>I am developing a windows application (server-client communication) in which server continuously sending the string message to the client and client reading that message through network-stream. After reading the message from the network-stream client flush the network-stream but old message still remain in network-stream.
  I think this is happening due to the continuous writing the message in network-stream in server-side.</p>
  
  <p>CODE
  Client :</p>
  
  <pre><code>clientSocket.Connect("192.XXX.X.XX", 8888);
  label1.Text = "Client Socket Program - Server Connected ...";
  NetworkStream serverStream = clientSocket.GetStream();
  string returndata = "";
  while ((true))
  {
      byte[] inStream = new byte[10025];
      serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
      returndata = System.Text.Encoding.ASCII.GetString(inStream);
      serverStream.Flush();
  }
  </code></pre>
  
  <p>Server Side :</p>
  
  <pre><code>TcpListener serverSocket = new TcpListener(8888);
  TcpClient clientSocket = default(TcpClient);
  NetworkStream networkStream = null;
  serverSocket.Start();
  clientSocket = serverSocket.AcceptTcpClient();
  networkStream = clientSocket.GetStream();
  Byte[] sendBytes = Encoding.ASCII.GetBytes(task);
  networkStream.Write(sendBytes, 0, sendBytes.Length);
  networkStream.Flush();
  </code></pre>
  
  <p>Please tell me how can i solve this problem?</p>