Socket.io without using the default namespace / room function

It was easier for me to just set up my own custom path for multiple endpoints such as

server side:

io.on('connection', function(client) {

  var username = client.handshake.headers.users[0].username;

  client.on(username+'_con1', function(data) {
      io.emit(username+'_con1',data);
  });

  client.on(username+'_con2', function(data) {
      io.emit(username+'_con2',data);
  });

}

Is the above approach correct? at least I can make it work.

+4
source share
2 answers

Depending on what you mean by right. This will create several events for the client.

It's hard to say if this is the best / right way without any context. But you have to look into the namespaces and rooms and decide for yourself! http://socket.io/docs/rooms-and-namespaces/

+1
source

, , , . -.

socket.io , ( ), , . .

, , , , . , .

, , , , - , , -.

. , . , .

- , , ( ).

+1

Source: https://habr.com/ru/post/1652674/


All Articles