I'm actually doing this myself in a websocket++ application, although I don't use the experimental branch.
What I do is that I create a UserData object (which I have defined) in the on_open, which takes the connection in the constructor. Then I place that object on the a std::map<std::string, connection_hdl>
.
The string is the serialized connection, which gives a way to uniquely identify it.
You could experiment with std::map<connection_hdl, UserData>
.
When I want to find the UserData i simply look up the connection in the map and it returns the UserData.
Then to get it thread-safe you need to do a boost::unique_lock<boost::mutex>
every time you access the std::map
.
Almost no std classes are thead-aware, so you should always add guards like this.
Edit: Here is the example in the stable websocket++ which shows one way of how to do this.