title: NodeJs tcp server
body: <p>i made i client tcp socket with c# and its work without any problem with c# server too</p>
  <p>first before i send data to the client i sent the header contain the data length adn some other</p>
  <p>now i tried same client code with nodeJs server TCP i got some issuse with Buffer size in nodeJs</p>
  <p>first this is my header</p>
  <pre><code> function writeInt(stream, int){
     var bytes = new Array(5)
     bytes[0] = 2
     bytes[1] = int &gt;&gt; 24
     bytes[2] = int &gt;&gt; 16
     bytes[3] = int &gt;&gt; 8
     bytes[4] = int
     bytes[5] = 0
   
     
     stream.write( Buffer.from(bytes))
    }
  </code></pre>
  <p>//1,2,3,4 the size of the buffer</p>
  <p>if i want to send message to client i use</p>
  <pre><code>var buf = Buffer.from(&quot;HELLO THIS IS A MESSAGE FROM SERVER&quot;);
  writeInt(sock, buf.length) 
  sock.write(buf);
  </code></pre>
  <p>that's work because i use string but when i tried to send integer i got issuse</p>
  <p>like</p>
  <pre><code>var buf = Buffer.from([1,2222,999,666]);
  writeInt(sock, buf.length) 
  sock.write(buf);
  </code></pre>
  <p>first thing the length of the buffer its wrong when i use <code>buf.length</code> it's return <code>4</code>!!</p>
  <p>i tried other method found it in NodeJs website like</p>
  <pre><code>let buf = Buffer.alloc(3);  // Init buffer without writing all data to zeros
  buf.writeUInt16BE(220);
  </code></pre>
  <p>and</p>
  <pre><code>let buf = Buffer.allocUnsafe(2);
  buf.writeUInt16BE(1234);
  </code></pre>
  <p>all those return wrong buffer length
  or buffer length not like i sent with function <code>writeInt</code></p>
  <p>that's happen only with <code>Integer</code> when i sent string its work without any issuse</p>