title: Sending int through socket in Java
body: <p>What is the best possible way to send an int through a socket in Java? Right now I'm looking at </p>
  
  <pre><code>sockout.write((byte)( length &gt;&gt; 24 ));
  sockout.write((byte)( (length &lt;&lt; 8) &gt;&gt; 24 ));
  sockout.write((byte)( (length &lt;&lt; 16) &gt;&gt; 24 ));
  sockout.write((byte)( (length &lt;&lt; 24) &gt;&gt; 24 ));
  </code></pre>
  
  <p>and then trying to rebuild the int from bytes on the other side, but it doesn't seem to work.  Any ideas?</p>
  
  <p>Thanks.</p>