title: Text communication between applications with TCP Sockets in VB.Net
body: <p>I've got a problem to make two applications to send text-data between themselves.
  The message is transmitted without any problems, the answer is received too. But, there is a lot of a "New line" char in the end of the string send/received on each side.
  I guess it's because of I'm reading the full buffer; I've tried to remove all Chr(10) and Chr(13); I also tried to trim the string, but it didn't worked.</p>
  
  <p>Here the code I use :</p>
  
  <p>Client Side :</p>
  
  <pre><code>Dim cl As New TcpClient
  cl.Connect("127.0.0.1", 2000)
  Dim str As NetworkStream = cl.GetStream
  Dim HelloInBytes As Byte() = Encoding.UTF8.GetBytes("Hello")
  str.Write(HelloInBytes, 0, HelloInBytes.Length)
  Dim Buffer(cl.ReceiveBufferSize) As Byte
  str.Read(Buffer, 0, cl.ReceiveBufferSize)
  Console.WriteLine(Encoding.UTF8.GetChars(Buffer))
  </code></pre>
  
  <p>Server Side :</p>
  
  <pre><code>Dim srv As New TcpListener(IPAddress.Any, 2000)
  srv.Start()
  Dim cl As TcpClient = srv.AcceptTcpClient
  Dim str As NetworkStream = cl.GetStream
  Dim buf(cl.ReceiveBufferSize) As Byte
  str.Read(buf, 0, cl.ReceiveBufferSize)
  Dim res As Byte() = Encoding.UTF8.GetBytes("World")
  str.Write(res, 0, res.Length)
  </code></pre>
  
  <p>Is there a way to "clean" the received string ?</p>
  
  <p>Thanks for help.</p>
  
  <p>EDIT : Solution :
  It Works with Harzcle solution.
  I found another solution which is to use this function on the received string :</p>
  
  <pre><code>Public Function CleanString(ByRef Str As String)
      Return Str.Replace(Encoding.UTF8.GetChars({0, 0, 0, 0}), Nothing)
  End Function
  </code></pre>
  
  <p>UTF8 works on 4 bytes, and when I read the stream and I put it into a buffer, if there is no char, the 4 bytes stay on a 0 value.</p>