title: TCP Client Reading
body: <p>Using vb.net I am trying to setup a simple app to open a tcp session to a host, write some data, read some data, then write some more and read some more.</p>
  
  <p>I can get it to write and read - but only once.. what am I doing wrong here. The second attempt to readline just times out. Using Telnet I can make it work no problem but there is something I am doing wrong here with the tcp client.</p>
  
  <p>There error I get is:</p>
  
  <blockquote>
    <p>Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.</p>
  </blockquote>
  
  <pre><code>        Dim client As New TcpClient(server, port)
          client.SendTimeout = 2000
          client.ReceiveTimeout = 4000
  
          'CONNECT
          Dim message As String = "HELLO"
          Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)
          Dim stream As NetworkStream = client.GetStream()
          Dim reader As New IO.StreamReader(stream)
  
          'WRITE THE DATA
          stream.Write(data, 0, data.Length)
          responseData = Convert.ToString(reader.ReadLine())
          If Not responseData.ToUpper.Contains("READY") Then
              Return responseData
          End If
  
          message = "OPTION"
          'WRITE THE DATA
          stream.Write(data, 0, data.Length)
          responseData = Convert.ToString(reader.ReadLine())
          If Not responseData.ToUpper.Contains("READY") Then
              Return responseData
          End If
  
          ' Close everything.
          stream.Close()
          client.Close()
  </code></pre>