Ad

Categorizing Socket.io Clients

- 1 answer

I'm working on a prototype application using Socket.io and having some trouble understanding the best approach to categorizing sockets.

My application serves multiple customers and has two types of clients:

  • Agent client running Socket.io client using Node.js
  • Web browser client running Socket.io client in the browser

How can my Socket.io server identify that a particular socket belongs to an agent of customer A versus an agent of customer B versus a web browser for customer C?

I read about namespaces and rooms but still a bit confused.

Ad

Answer

If identification doesn't require security, simply let clients send a special event indicating what type of agent/browser they're, upon connection. On the server-side, when that event is received, set the identifier into the respective socket object.

If identification require security, you can grab the user session via https://github.com/oskosk/express-socket.io-session.

Ad
source: stackoverflow.com
Ad