title: best way to send and receive multiple variable data through socket
body: <p>I am working on a game project that uses sockets for sending and receiving data. Client games are Unity, the server is ASP.Net.</p>
  
  <p>As we all know on sockets you just can send and receive bytes. So, what is the best way for me to send and receive multiple variables like speed direction and so on.</p>
  
  <p>I think the best way is to concat all variables to a string and convert that string to a byte and after that send and un concat the string at the other side. But maybe its not the best way and there might be other ways especially in C#. Here is my pseudocode that I think can work well:</p>
  
  <pre><code> int position,rotation;
   string data=concat(data,position,rotation);
   byte[] byteBuffer = Encoding.ASCII.GetBytes(data);
   socket.send(bytebuffer);
  </code></pre>
  
  <p>I think this way can not be efficient enough. Can I find some other way?</p>