title: Why TCPClient doesn't receive text data
body: <p>I have two projects: client and server.</p>
  <p>Server code:</p>
  <pre><code>static void Main()
  {
      var listener = new TcpListener(System.Net.IPAddress.Loopback, 13000);
      listener.Start();
  
      using (var client = listener.AcceptTcpClient())
      {
          var stream = client.GetStream();
          var textStream = new StreamReader(stream);
  
          while (true)
          {
              var line = textStream.ReadLine();
  
              if (line == &quot;&quot;) continue;
              if (line == null) continue;
  
              var clientIp = IPAddress.Parse(line.Split(':').First());
              var clientPort = int.Parse(line.Split(':').Last());
              var response = new LobbyConnectionResponse(StatusCode.OK, &quot;Connected&quot;, new List&lt;Player&gt;(), new Leader(&quot;J&quot;, Guid.NewGuid()));
              SendResponseToClient(clientIp, clientPort, response);
              Console.WriteLine(line);
              Thread.Sleep(lobbyResponseTimeout);
          }
      }
  
      listener.Stop();
  }
  
  static Task SendResponseToClient(IPAddress ip, int port, LobbyConnectionResponse response)
  {
      var task = Task.Run(() =&gt;
      {
          using (var tcpClient = new TcpClient())
          {
              tcpClient.Connect(ip, port);
              var stream = tcpClient.GetStream();
              var textStream = new StreamWriter(stream);
              string jsonString = JsonSerializer.Serialize(response);
              textStream.WriteAsync(jsonString);
              stream.FlushAsync();
          }
      });
  
      return task;
  }
  </code></pre>
  <p>Client code:</p>
  <pre><code>static void Main()
  {
      StartListener();
  
      using (var client = new TcpClient())
      {
          client.Connect(&quot;127.0.0.1&quot;, 13000);
          var stream = client.GetStream();
          var textStream = new StreamWriter(stream);
          textStream.WriteLine(&quot;127.0.0.1:12000&quot;);
          textStream.Flush();
      }
  
      while(true)
          Thread.Sleep(1000);
      Thread.Sleep(1000);
  }
  
  static Task StartListener()
  {
      var task = Task.Run(() =&gt;
      {
          var listener = new TcpListener(System.Net.IPAddress.Loopback, 12000);
          listener.Start();
          while (true)
          {
              using (var client = listener.AcceptTcpClient())
              {
                  var stream = client.GetStream();
                  var textStream = new StreamReader(stream);
                  while (true)
                  {
                      if (stream.DataAvailable)
                          Console.WriteLine(&quot;hfdsgdf&quot;);
                      var line = textStream.ReadLine();
                      if (line == null || line == &quot;&quot;) continue;
                      var response = (LobbyConnectionResponse)JsonSerializer.Deserialize(stream, typeof(LobbyConnectionResponse));
                      Console.WriteLine(response.Description);
                      Thread.Sleep(100);
                  }
              }
              Thread.Sleep(100);
          }
          listener.Stop();
      });
      return task;
  }
  </code></pre>
  <p>On the server's console, I had message:&quot;127.0.0.1:12000&quot; but client's console are empty, why client doesn't receive my text data? 0 Exceptions, clients code just looping infinity and every iteration continues because line == null</p>
  <p>When I tried to make that on a single port ( server and client), nothing worked. I want that client get my JSON and deserialize it into class instance.</p>