Question

Is there a way to track per user data with websocket++ 0.3X?

I want to be able to identify them so to keep track of what they're looking at and what should be sent to them. Take stack as an example: while you're looking at this question, a websocket could (and I think does) keep in memory that you're looking at this question and send you the appropriate updates like votes, new comments & answers, and StackExchange updates in the upper left corner.

Also, the users need to be able to identified. Is there a session id inherent in websockets that are already hiding in websocket++? If not, how does websocket++ track users?

Was it helpful?

Solution

The simplest way is, as you mentioned in your answer, to use connection_hdl as a key for an associative container that stores any other data you need. WebSocket++ does have some other options for cases where that sort of lookup would be too costly.

Since this is a common question, I've written up some more formal examples & documentation on how to do this here: http://www.zaphoyd.com/websocketpp/manual/common-patterns/storing-connection-specificsession-information.

OTHER TIPS

Ah, OK. It was hiding in plain sight all along. http://www.zaphoyd.com/websocketpp/manual/building-program-websocket

The connection handle is a token that uniquely identifies the connection that received the message. It can be used to identify where to send reply messages or stored and used to push messages later. The type of the connection handle is websocketpp::connection_hdl.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top