title: C# Chat clients with multiple threads (read+write at the same time)
body: <p>How do I make the client read from the stream (for messages of other clients sent to the stream) at the same time as being able to write to them?</p>
  
  <p>I tried creating different threads on the client side (did I even do it right?), however I can still only write to the server, without any response. This is what I'm getting right now: </p>
  
  <p>(Server-Client-Client) </p>
  
  <p><img src="https://i.stack.imgur.com/vsj80.png" alt=""></p>
  
  <p>Client:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Net.Sockets;
  using System.IO;
  using System.Threading;
  
  
  namespace Klientas
  {
      class Klientas
      {
          public static void Write()
          {
              while (true)
              {
                  TcpClient clientSocket = new TcpClient("localhost", 1000);
                  string str = Console.ReadLine();
                  BinaryWriter writer = new BinaryWriter(clientSocket.GetStream());
                  writer.Write(str);
              }
          }
          public static void Read()
          {
              while (true)
              {
                  TcpClient clientSocket = new TcpClient("localhost", 1000);
                  BinaryReader reader = new BinaryReader(clientSocket.GetStream());
                  Console.WriteLine(reader.ReadString());
              }
          }
  
          static void Main(string[] args){
              Thread ctThread = new Thread(Write);
              Thread ctThread2 = new Thread(Read);
              ctThread2.Start();
              ctThread.Start();
  
             }
      }    
  }
  </code></pre>
  
  <p>Server: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Net.Sockets;
  using System.IO;
  
  namespace MultiServeris
  {
      class Multiserveris
      {
          static void Main(string[] args)
          {
              TcpListener ServerSocket = new TcpListener(1000);          
              ServerSocket.Start();                                    
  
              Console.WriteLine("Server started.");
              while (true)
              {
                  TcpClient clientSocket = ServerSocket.AcceptTcpClient();       
                  handleClient client = new handleClient();                      
                  client.startClient(clientSocket);
              }
  
  
          }
      }
  
      public class handleClient
      {
          TcpClient clientSocket;                                   
          public void startClient(TcpClient inClientSocket)
          {
              this.clientSocket = inClientSocket;
              Thread ctThread = new Thread(Chat);                   
              ctThread.Start();
          }
  
  
  
          private void Chat()
          {                  
              while (true)
              {
                  BinaryReader reader = new BinaryReader(clientSocket.GetStream());
                  Console.WriteLine(reader.ReadString());
              }
          }
  
  
  
      }
  
  }
  </code></pre>