title: Using Socket.IO in server side with socket.io-client
body: <p>I use the socket.io in my app.js and configure it with express framework, now when I run the application both of application and socket.io will start and I can emit messages between client and app.js.</p>
  
  <p>app.js (Server)</p>
  
  <pre><code>var express = require('express'),
      app = express(),
      http = require('http'),
      server = http.creatServer(app),
      socket = require('socket.io'),
      io = socket.listen(server);
  
  server.listen(3000);    
  
  io.sockets.on('connection', function(client){
      client.on('message', function(msg){
          io.sockets.emit('message', msg);
      });
  });
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>&lt;script type="text/javascript" src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      var server = io.connect('http://127.0.0.1:3000');
      server.emit('message', 'Hello World');
  &lt;/script&gt;
  </code></pre>
  
  <p>But I want to use socket in other Controllers... I use "socket.io-client (<a href="https://npmjs.org/package/socket.io-client" rel="nofollow">https://npmjs.org/package/socket.io-client</a>)", now I want to get messages 
  that emitted from app.js to all sockets.</p>
  
  <p>controller.js (Server)</p>
  
  <pre><code>var io = require('socket.io-client'),
      socket = io.connect('127.0.0.1', {
          port: 3000
      });
  
  socket.on('connect', function(){
      console.log('CONNECTED!!');
      socket.on('message', function(msg){
          console.log("New message:", msg);
      });
  });
  </code></pre>
  
  <p>It can't connect!</p>