title: How to connect to a socket.io server from different host?
body: <p>I have a site say <strong>mydomain/home.php</strong></p>
  
  <p>Now I have set up a <strong>NodeJs</strong> server say at <strong>23.23.234.22/home</strong> (/home is a <strong>get</strong> route). I have written the code for <strong>socket.io</strong> server
  and finally server is running.</p>
  
  <p>Now I want to write client side code in <strong>home.php</strong> which would be similar to the code give below. </p>
  
  <p>What I want is to send a request to <strong>23.23.234.22/home</strong> and I should see a socket response in <strong>console</strong> of browser when home.php is open. I want this to work every time I hit a request to it, not only when the server is connected.</p>
  
  <p>I know, with this code things won't work. I don't know how
  to do this. So what additional changes do I need?</p>
  
  <p>socket.js</p>
  
  <pre><code>var express = require('express');
  var app = express();
  
  var bodyParser = require('body-parser');
  app.use(bodyParser.json({type: '*/*'}));
  var server = require('http').createServer(app);
  
   app.get('/home', function(req, res){
     //WRITE SOCKET SERVER CODE HERE?
   });
  
  var io = require('socket.io')(server);
  
  app.use(express.static('/opt/lampp/htdocs/testproject/node_modules'));
  app.use(express.static('/opt/lampp/htdocs/testproject/'));
  
  io.on('connection', function(client) {
      console.log("connected");
     client.emit("message", "Some thing to show");
  });
  server.listen(8080);
  </code></pre>
  
  <p>home.php</p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  
  //CHANGE FOLLOWING ADDRESS?
      var socket = io.connect('http://23.23.234.22/home');
      socket.on('connect', function(data) {
          console.log("Connected...");
  
      });
  
      socket.on("message", function(data){
          console.log(data);
      });
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>