title: Socket IO get data from URL
body: <p>Greetings,</p>
  
  <p>I'm trying to broadcast messages to users based on the data I get from a URL. The data returned from the URL will be json. I'm very new to node.js and socket.io and I have node.js and socket.io installed. I'm just not 100% sure on how to get the data I need to broadcast to the clients via URL. What other requires do I need?</p>
  
  <p>My server file server.js</p>
  
  <pre><code>var http = require('http'),  
  io = require('socket.io'), 
  // Do I need another require here?    
  
  server = http.createServer(function(req, res){ 
   // your normal server code 
   res.writeHead(200, {'Content-Type': 'text/html'}); 
   //res.end('&lt;h1&gt;Hello world&lt;/h1&gt;'); 
  });
  server.listen(8080);
  
  // socket.io 
  var socket = io.listen(server); 
  socket.on('connection', function(client){ 
  
    //I'm not sure where/how to get data from a URL
    function getMessages() {
  
      var request = messageClient.request("GET", "json.php", {"host": "myurl.com"});
  
      // Is this how I send the data to the client?
      socket.broadcast(request);
  
      //request.end();
    }
  
    setInterval(getMessages, 1000);
  
    client.on('message', function(){ … }) 
    client.on('disconnect', function(){ … }) 
  
  });
  </code></pre>
  
  <p>My client</p>
  
  <pre><code>// Load jQuery too
  &lt;script src="http://pathtojquery.js"&gt;&lt;/script&gt; 
  &lt;script src="http://{node_server_url}/socket.io/socket.io.js"&gt;&lt;/script&gt; 
  &lt;script&gt; 
   var socket = new io.Socket({node_server_url}); 
   socket.connect();
   socket.on('connect', function(){ … }) 
   socket.on('message', function(data){
     // Use jquery to handle the json data here and display message to the clients
     // I can handle this part as long as 'data' is json
  
   }) 
   socket.on('disconnect', function(){ … }) 
  &lt;/script&gt; 
  </code></pre>