title: nodejs tcp socket write
body: <p>I am having trouble writing some data to a tcp socket in nodejs.</p>
  
  <p>Here is the adobe flex code i am replacing.</p>
  
  <pre><code>private function SendRequestHello():void
  {
      writeUnsignedInt( 0);                                                   /* Request Type. */
      writeUnsignedInt( 16);                                                  /* Length. */
      writeByte( OPCODE_HELLO);                                               /* Opcode. */
      writeUnsignedInt( m_nOwnID / 0x100000000);                              /* GPS Server ID. */
      writeUnsignedInt( m_nOwnID &amp; 0xffffffff);                               /* GPS Server ID part 2. */
      writeUnsignedInt( 3 &lt;&lt; 24);                                             /* GPS Server Version (my version). */
      writeUnsignedInt( 3 &lt;&lt; 24);                                             /* Oldest supported Server Version. */
      FlushWithCatch();
  }
  </code></pre>
  
  <p>and here is my attempt in node</p>
  
  <pre><code>clients[socket.id].fwd.connect(26000, clients[socket.id].serverip, function() {
      console.info(socket.id + ' connected to gps forwarder: ' + clients[socket.id].serverip + ':26000');
      clients[socket.id].fwdConnected = true;
  
      clients[socket.id].fwd.write( 0);                                                   /* Request Type. */
      clients[socket.id].fwd.write( 16);                                                  /* Length. */
      clients[socket.id].fwd.write( 1);                                                   /* Opcode. */
      clients[socket.id].fwd.write( clients[socket.id].AppID / 0x100000000);              /* GPS Server ID. */
      clients[socket.id].fwd.write( clients[socket.id].AppID &amp; 0xffffffff);               /* GPS Server ID part 2. */
      clients[socket.id].fwd.write( 3 &lt;&lt; 24);                                             /* GPS Server Version (my version). */
      clients[socket.id].fwd.write( 3 &lt;&lt; 24);                                             /* Oldest supported Server Version. */
  }); 
  </code></pre>
  
  <p>I get <strong>TypeError: invalid data</strong></p>
  
  <pre><code>TypeError: invalid data
  at Socket.write (net.js:617:11)
  at Socket.&lt;anonymous&gt; (C:\**\index.js:84:30)
  at Socket.g (events.js:260:16)
  at emitNone (events.js:72:20)
  at Socket.emit (events.js:166:7)
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1045:10)
  </code></pre>
  
  <p>Are there any different write options i should be using here?</p>
  
  <p>EDIT: <a href="https://github.com/yi/node-bytearray" rel="nofollow">https://github.com/yi/node-bytearray</a> Looks like an interesting plugin, but i do not understand the usage for it. How would i 'writeUnsignedInt' into my net socket?</p>