title: Synchronously connecting to a socket in node js
body: <p>I have a simple node js server and I would like to connect to another socket, read data, and return it to the client. </p>
  
  <pre><code>http.createServer(function(req, res){
       var sock = new Socket();
          sock.connect(80, "www.google.com", function(){
              console.log("Connected to google..");
              sock.write("GET /\r\n\r\n");
          }); 
          sock.on("data", function(data){
              console.log(data.toString()); 
              res.writeHead(404, {"Content-type": "text/plain"});
              res.write(data, "binary");
              res.end(); 
              sock.end();
          });
          sock.on("end", function(){
              console.log("Disconnected from socket..");
          }); 
  }, 8080);
  </code></pre>
  
  <p>But this obviously doesn't work because the call to data callback is asynchronous. </p>
  
  <p>So how can I accomplish this with node js?</p>