title: How to emit from the default namespace to a custom namespace?
body: <p>I have a React app using Socket.io. I use the default namespace <code>/</code> and a custom namespace <code>/test</code>. I need to be able to emit from a namespace to another, but I only managed to get it work from the custom to the default.</p>
  
  <p>On client side, the event listener is on the root (<code>App.js</code>):</p>
  
  <pre><code>componentDidMount() {
    socket.on('test_listener', (data) =&gt; {
      // Some code
    })
  }
  </code></pre>
  
  <p>The connection is initialized with redux:</p>
  
  <pre><code>import socketIOClient from 'socket.io-client';
  
  const initialState = {
    initializeSocket: socketIOClient('http://localhost:3000/'),
    ...
  }
  </code></pre>
  
  <p>On server side, here is the code:</p>
  
  <pre><code>io.on('connection', function (socket) { 
  
    socket.on('something', (data) =&gt; {
  
      io.of('/test').emit('test_listener', data); // Not working
      socket.broadcast.emit('test_listener', data); // Is working
  
    })
  
  });
  </code></pre>
  
  <p>I know for sure that <code>io.of('namespace').emit('event_name', data);</code> is supposed to work as it is settled in the <a href="https://socket.io/docs/emit-cheatsheet/" rel="nofollow noreferrer">Socket.io's Emit cheatsheet</a>. And the event listener on client side is working since I get something with the <code>broadcast.emit</code>.</p>
  
  <p>Plus, I can emit from <code>/test</code> to <code>/</code> with this code:</p>
  
  <pre><code>socket.on('join_namespace_test', data =&gt; {
  
    // [...] Some code to check if the namespace exists
  
    io.of('/test').on('connection', function (nspSocket) {
  
      nspSocket.on('do_something', (data) =&gt; {
        io.of('/').emit('another_action', data); // This one is working fine
      })
  
    })
  
    // [...] Some code to add the user to the namespace /test (switching from default)
  }
  </code></pre>
  
  <p><strong>Any idea why the emit from <code>/</code> to <code>/test</code> is not working?</strong>
  I don't get any error, nothing happens.</p>
  
  <hr>
  
  <p><strong>Edit:</strong> after further research, I found out <a href="https://stackoverflow.com/a/48037918/9718056">this post</a>:</p>
  
  <blockquote>
    <p>You can't "switch" namespaces on an existing connection. You connect to a specific namespace when the connection is made and once made, it can't be changed.</p>
  </blockquote>
  
  <p>To be sure that the problem doesn't come from another part of the project, I reproduced the issue on a fiddle. The emit from default to custom still doesn't work and I also noticed that the <code>broadcast</code> has a strange behaviour when the client switch from default to custom and then go back to default (it emits to the sender while it shouldn't).</p>
  
  <p>So, given the fact that the issue might be the way the client switch between the default and the custom namespace and not the emit itself, maybe rooms would be a better option? Or maybe I should find a way to drop the connections before switching, but is it recommended?</p>