Reputation: 397
I am building a complex chatting application, using WebSockets. I use Node.JS's Socket.IO library to implement the protocol. Should I create a separate namespace for each Chat, Or separate room for each Chat?
What is the main difference between Namespaces and Rooms in Socket.IO?
Upvotes: 2
Views: 2930
Reputation: 124
Typically rooms are used if all the clients are of the same type.
Use namespaces if there are different types of clients. For example, anonymous users and authenticated users. In this case one may need to process incoming connection requests differently.
var guest = io.of('/guest');
guest.on('connection', function(socket) {
console.log('A guest client connected');
});
var user = io.of('/user');
user.on('connection', function(socket) {
var authenticated = authenticate(); //authenticate the user
if (!authenticated) {
// log attempt and disconnect the client
}
});
Upvotes: 4