title: XmlSerializer.Deserialize blocks over NetworkStream
body: <p>I'm trying to sends XML serializable objects over a network stream.</p>
  
  <p>I've already used this on an UDP broadcast server, where it receive UDP messages from the local network. Here a snippet of the server side:</p>
  
  <pre><code>while (mServiceStopFlag == false) {
      if (mSocket.Available &gt; 0) {
          IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, DiscoveryPort);       byte[] bData;
  
      // Receive discovery message
      bData = mSocket.Receive(ref ipEndPoint);
      // Handle discovery message
      HandleDiscoveryMessage(ipEndPoint.Address, bData);
      ...
  </code></pre>
  
  <p>Instead this is the client side:</p>
  
  <pre><code>IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Broadcast, DiscoveryPort);
  MemoryStream mStream = new MemoryStream();
  byte[] bData;
  
  // Create broadcast UDP server
  mSocket = new UdpClient();
  mSocket.EnableBroadcast = true;
  
  // Create datagram data
  foreach (NetService s in ctx.Services)
      XmlHelper.SerializeClass&lt;NetService&gt;(mStream, s);
  bData = mStream.GetBuffer();
  
  // Notify the services
  while (mServiceStopFlag == false) {
      mSocket.Send(bData, (int)mStream.Length, ipEndPoint);
      Thread.Sleep(DefaultServiceLatency);
  }
  </code></pre>
  
  <p>It works very fine. </p>
  
  <p>But now i'me trying to get the same result, but on a <code>TcpClient</code> socket, but the using directly an <code>XMLSerializer</code> instance:</p>
  
  <p>On server side:</p>
  
  <pre><code>    TcpClient sSocket = k.Key;
  ServiceContext sContext = k.Value;
  Message msg = new Message();
  
  while (sSocket.Connected == true) {
      if (sSocket.Available &gt; 0) {
          StreamReader tr = new StreamReader(sSocket.GetStream());
          msg = (Message)mXmlSerialize.Deserialize(tr);
  
          // Handle message
          msg = sContext.Handler(msg);
          // Reply with another message
          if (msg != null)
              mXmlSerialize.Serialize(sSocket.GetStream(), msg);
      } else
          Thread.Sleep(40);
  }
  </code></pre>
  
  <p>And on client side:</p>
  
  <pre><code>NetworkStream mSocketStream;
  Message rMessage;
  
  // Network stream
  mSocketStream = mSocket.GetStream();
  
  // Send the message
  mXmlSerialize.Serialize(mSocketStream, msg);
  // Receive the answer
  rMessage = (Message)mXmlSerialize.Deserialize(mSocketStream);
  
  return (rMessage);
  </code></pre>
  
  <p>The data is sent (Available property is greater than 0), but the method <code>XmlSerialize.Deserialize</code> (which should deserialize the Message class) blocks.</p>
  
  <p>What am I missing?</p>