title: DataWriter.WriteUInt32 equivalent in .NET Socket?
body: <p>We have a UWP app that has a Listener which uses <strong>DataReader.ReadUInt32()</strong> where we specify the length of the message we pass. Before, it was only listening from other UWP apps which uses <strong>DataWriter.WriteUInt32()</strong> so it was properly able to read it.</p>
  
  <p>Now we are adding .NET apps that communicate with the UWP apps. The problem is, Socket in .NET doesn't seem to have an equivalent of the WriteUInt32() method. So what happens is, ReadUInt32() seems to output incorrect data (ex. 825373492).</p>
  
  <p>Below is a code snippet of our Sender and Listener:</p>
  
  <p>Sender:</p>
  
  <pre><code>            using (var socket = new StreamSocket())
              {
                  var cts = new CancellationTokenSource();
                  cts.CancelAfter(5000);
                  await socket.ConnectAsync(hostName, peerSplit[1]).AsTask(cts.Token);
  
                  var writer = new DataWriter(socket.OutputStream);
                  if (includeSize) writer.WriteUInt32(writer.MeasureString(message));
                  writer.WriteString(message);
                  await writer.StoreAsync();
                  writer.DetachStream();
                  writer.Dispose();
              }
  </code></pre>
  
  <p>Listener:</p>
  
  <pre><code>                // Read first 4 bytes (length of the subsequent string).
                  var sizeFieldCount = await reader.LoadAsync(sizeof(uint));
                  if (sizeFieldCount != sizeof(uint))
                  {
                      // The underlying socket was closed before we were able to read the whole data.
                      reader.DetachStream();
                      return;
                  }
                  // Read the string.
                  var stringLength = reader.ReadUInt32();
                  var actualStringLength = await reader.LoadAsync(stringLength);
                  if (stringLength != actualStringLength)
                  {
                      // The underlying socket was closed before we were able to read the whole data.
                      return;
                  }
  
                  var message = reader.ReadString(actualStringLength);
  </code></pre>
  
  <p>Is there an equivalent of WriteUInt32() in .NET Socket?</p>