title: Node.js UDP Stream
body: <p>Im trying to "port" some code from PHP into Node and im struggling to find out how to get it working. Im trying too connect to an RCON server over UDP.
  Here is a simplified version of the PHP version which works:</p>
  
  <pre><code>$address = '1.2.3.4:1234';
  $password = 'password';
  
  $socket = stream_socket_client('udp://' . $address, $errno, $errstr);
  stream_set_blocking($socket, 0);
  
  $loginRequest = chr(0x45) . $password;
  stream_socket_sendto($socket, $loginRequest, 0, $address);
  echo 'RCON Login Request Sent' . PHP_EOL;
  echo $loginRequest . PHP_EOL;
  echo PHP_EOL;
  
  do {
      $data = stream_socket_recvfrom($socket, 127, 0, $address);
  } while (!$data);
  echo 'RCON Received Response' . PHP_EOL;
  echo $data . PHP_EOL;
  </code></pre>
  
  <p>Here is what I have got in Node, which doesnt seem to do anything. I dont even get any acknowledgment of a connection from the server.</p>
  
  <pre><code>var address = '1.2.3.4';
  var port = '1234';
  var password = 'password';
  
  var socket = require('dgram').createSocket('udp4');
  
  socket.on('message', function (msg, from) {
      console.log(msg);
  });
  
  socket.on('listening', function () {
      var loginPacket = new Buffer(String.fromCharCode(0xff) + password);
      socket.send(loginPacket, 0, loginPacket.length, port, address, function (err, bytes) {
          console.log('packet sent');
      });
  });
  
  socket.on('error', function (err) {
      console.log('ERROR: ', err);
  });
  
  socket.bind(0);
  </code></pre>
  
  <p>Any help with this would be great! maca134</p>