Edit: This question was asked due to inadequate knowledge of the EventMachine
.
With the Socket.IO interface, I can multiplex connections with "channels". How would I start a Socket.IO server, but add channels without having to stop/start the server?
var io = require('socket.io').listen(80);
var chat = io
.of('/chat')
.on('connection', function (socket) {
socket.emit('a message', {
that: 'only'
, '/chat': 'will get'
});
chat.emit('a message', {
everyone: 'in'
, '/chat': 'will get'
});
});
var news = io
.of('/news')
.on('connection', function (socket) {
socket.emit('item', { news: 'item' });
});
This code example from Socket.IO shows starting the server, then creating two channels called chat
and news
. What I if I started the server with chat
, but wanted to add news
without any interruption to chat
? How would I add the channel?
You don't need restart your server to add namesapaces. Just start using new namespace. In your example both namespaces (chat
and news
) created after server start.