var proxyStream = connect(server, function(err, stream, bin) {
      if (err) { cb(hostId, err); return; }
      localStream.on("end", function() {
        cb(hostId, "Local stream closed");
      });
      //stream.on("data", function(buf) { console.log("Data from server:",buf,""+buf) });
      BinaryBuffer.writeWord(stream, mode);   // 0x02 = command ConnectVNC, 0x04 = command ConnectTCP
      BinaryBuffer.writeVbStr(stream, hostId + (remotePort ? ":"+remotePort : ""));
      bin.request("word", function(errLen) {
        if (errLen > 0) {
          bin.request(errLen, function(err) {
            console.log("ERROR: "+err);
            cb(hostId, "ERROR: "+ err);
          });
          return;
        }

        cb(hostId, true);

        bin.stopListening();

        localStream.write(bin.buffer);

        localStream.pipe(stream);
        stream.pipe(localStream);
      })
    });
 connect(server, function(err, stream, bin) {
   if (err) { server.error=err; cb(err,null); return; }
   BinaryBuffer.writeWord(stream, 0x01);  // 0x01 = command ListHosts
   BinaryBuffer.writeVbStr(stream, "");
   bin.request(4, function(res) {
     var resLen = res.readUInt16BE(2);
     bin.request(resLen, function(hostlist) {
       cb(null, hostlist.toString());
     })
   })
 }).on("error", function(err) {
 connect(server, function(err, stream, bin) {
   if (err) { cb(err,false); return; }
   BinaryBuffer.writeWord(stream, 0x03);   // 0x03 = command WakeOnLan
   BinaryBuffer.writeVbStr(stream, hostId);
   bin.request("word", function(errLen) {
     if (errLen > 0) {
       bin.request(errLen, function(err) {
         console.log("ERROR: "+err);
         cb(""+err, false);
       });
     } else {
       cb(null, true);
     }
   });
 }).on("error", function(err) {