title: How can I get socket.io to work with subdomains?
body: <p>I'm running a node application that conditionally <code>.use</code>s other applications based on the subdomain of the HTTP request. The code for that is as below:</p>
  
  <pre><code>var server = http.createServer(app);
  </code></pre>
  
  <p>...</p>
  
  <pre><code>global.socket = io.listen(server);
  </code></pre>
  
  <p>...</p>
  
  <pre><code>subdomains.forEach(function (subdomain) {
      var vhost = (subdomain == '_' ? '' : subdomain + '.') + domain;
      app.use(express.vhost(vhost, require('./' + subdomain)));
  });
  </code></pre>
  
  <p>Now suppose I want to use socket.io in two different subdomains. They both have access to the same socket, since it's running on the same port. Yet if I try to connect to <code>http://sub1.domain.tld/</code>, any broadcasts are also sent to <code>http://sub2.domain.tld/</code>.</p>
  
  <p>Is there any way I can restrict broadcast, emit, &amp;c. based on the subdomain of the connection?</p>