title: Sending Command with CR to TCP server in C#
body: <pre><code>public void ClientSend(string msg)
  {
      stream = client.GetStream(); //Gets The Stream of The Connection
      byte[] data; // creates a new byte without mentioning the size of it cuz its a byte used for sending
      data = Encoding.Default.GetBytes(msg); // put the msg in the byte ( it automaticly uses the size of the msg )
      int length = data.Length; // Gets the length of the byte data
      byte[] datalength = new byte[4]; // Creates a new byte with length of 4
      datalength = BitConverter.GetBytes(length); //put the length in a byte to send it
      stream.Write(datalength, 0, 4); // sends the data's length
      stream.Write(data, 0, data.Length); //Sends the real data
  }
  </code></pre>
  
  <p>I am trying to send commands to <strong>Videojet Printer TTO</strong> which is TCP server in my case when I send <code>GST&lt;cr&gt;</code> through hercules (TCP Client) it send command properly to the printer as GST where as when I send <code>textbox.text = "GST" + "\r"</code> from my C# TCP Client utility Printer doesn't responds. It is observed in Hercules that when I send <code>textbox.text = "GST" + "\r"</code> in Hercules TCP server it recieves as <code>GST\r</code> not as GST that means CR is passing with the String it is going as a string.</p>
  
  <pre><code>richtextbox.AppendText("\r\n" + now.ToString() + " Sent : \r\n" + textbox.Text + "\r");
  </code></pre>