title: How do you deserialize protobuf messages in c# read into a byte array via sockets?
body: <p>I'm new to both c# and protocoll buffers, and am trying to send a simple message from python to a c# program. So far I haven't got it to work. From python I send the following:</p>
  
  <pre class="lang-py prettyprint-override"><code>sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  serverAddress = ('localhost', 2211)
  sock.bind(serverAddress)
  sock.listen(1)
  connection, clientAddress = sock.accept()
  
  message = protos.testproto_pb2.Coordinate()
  message.Row = 12.3
  message.Col = 12.4
  connection.sendall(message.SerializeToString())
  
  connection.close()
  </code></pre>
  
  <p>In c# I connect to the socket and receive the Data into a byte array:</p>
  
  <pre class="lang-cs prettyprint-override"><code>Byte[] bytesReceived;
  var server = (ip:"127.0.0.1", port: 2211);
  
  IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(server.ip), server.port);
  Socket mySocket = 
      new Socket(serverEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
  
  Coordinate Coord = new Coordinate{Row = 0, Col = 0};
  
  mySocket.Connect(serverEndPoint);
  
  bytes = mySocket.Receive(bytesReceived, bytesReceived.Length, 0);
  
  Coord = Coordinate.Parser.ParseFrom(bytesReceived);
  
  </code></pre>
  
  <p>My *.proto is a very simple message with two floats:</p>
  
  <pre class="lang-c prettyprint-override"><code>message Coordinate{
      //coordinates
      float Row = 1;
      float Col = 2;
  }
  </code></pre>
  
  <p>I've tried various things resulting various errors. When I don't trim the byte removing zero bytes i get <code>Google.Protobuf.dll: 'Protocol message contained an invalid tag (zero).'</code>. I then tried only reading the bytes that contain data and get: <code>Google.Protobuf.dll: 'While parsing a protocol message, the input ended unexpectedly in the middle of a field.</code></p>
  
  <p>I also tried some other protobuf functions e.g. <code>Coord.MergeFrom()</code> etc... but so far no luck. Can anyone let me know what I'm doing wrong? </p>
  
  <p>I could be either with the simple sockets or with the protobuf deserialization. </p>