title: Constant Recieve TcpClient
body: <p>I need to communicate with an old Java TCP server.
  The way it works is that I need to establish a connection by sending a request, after the request
  I am subscribed to events and the server sends me data through the connection so I need to
  keep listening for data always. This is what I have and it works for some time but after a while it stops receiving.</p>
  <pre><code>            string logon = GetLogon();
              client = new TcpClient(SERVER_IP, PORT_NO);
              NetworkStream nwStream = client.GetStream();
              byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(logon);
              nwStream.Write(bytesToSend, 0, bytesToSend.Length);
  
              while (client.Connected)
              {
                  byte[] bytesToRead = new byte[client.ReceiveBufferSize];
                  int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
                  var message = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                  this.ProcessMessage(message);
              }
  </code></pre>
  <p>I poll the server every minute in a seperate function to check if the connection is open and it always is even tho I dont get any data.</p>
  <pre><code>            bool poll = client.Client.Poll(1000, SelectMode.SelectRead);
              bool data = (client.Client.Available == 0);
  </code></pre>
  <p>This works but after about 20 to 60 minutes I stop receiving from the server. Thank you for your help.</p>