title: Sending and Receiving XML data over TCP
body: <p>I've been trying to figure out how to send and receive XML Data over a TCP Server. I'm coming from a java programming background so i'm a bit out of my depth here. My program works if i'm sending just plain text, however once I try to send the xml data it just hangs. The server never receives the message.
  I've been searching for code to do this and haven't found any luck, i've seen lots of code samples online that don't work. please if any of you can solve this problem I would be very grateful. </p>
  
  <p>Please I'm looking for code samples here, not explanations on what I should do to fix it. I've only been coding C# for a few days.
  Here is the sample XML Request.</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;ClientRequest&gt;
        &lt;Product&gt;AGENT&lt;/Product&gt;
        &lt;Method&gt;GET_SYSTEM_INFO&lt;/Method&gt;
        &lt;ClientId&gt;UMOHB&lt;/ClientId&gt;
        &lt;Params&gt;
          &lt;Param Value="umohb" Key="username" /&gt;
          &lt;Param Value="password" Key="password" /&gt;
          &lt;Param Value="localhost" Key="hostname" /&gt;
        &lt;/Params&gt;
      &lt;/ClientRequest&gt;
  </code></pre>
  
  <p>Here is my TCP Client Code</p>
  
  <pre><code>    public static void sendStringRequest(String hostname, int port, String message)
      {
          String response = String.Empty;
          TcpClient client = getConnection(hostname, port);
  
          Console.WriteLine(message);
  
          NetworkStream stream = client.GetStream();
          StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
          writer.AutoFlush = false;
          writer.Write(Encoding.UTF8.GetBytes(message).Length);
          writer.Write(message);
          writer.Flush();
  
          StreamReader reader = new StreamReader(stream, Encoding.UTF8);
          response = reader.ReadLine();
  
          stream.Close();
      }
  </code></pre>