<div>Hello,<br></div><div><br></div><div>I've written a fairly standard websocket handler using Cowboy 2.4.  It correctly accepts websockts, and handles messages in both directions.  Cowboy's built in functionality makes this simple.<br></div><div><br></div><div>However, I can't find a way to store any state for a websocket connection.  Cowboy creates a separate PID for each connection, so theoretically we should be able to have each PID keep state (like any other erlang process or gen_server.) I'd like users to be able to do things like authenticate, set preferences, etc. for a websocket connection.  the easiest way to handle this would be to simply save a few variable sin state, as we do in any other gen_server process.  <br></div><div><br></div><div>The Cowboy Websocket handler *does* have a state variable that gets passed through calls, HOWEVER there is no way to define the state record like we'd do with other gen_server processes.  I tried simply adding the record definition to the top of the handler file (standard workflow for gen_server), but Cowboy then crashes with an undefined record error when I try to use the state record.<br></div><div><br></div><div>Does anybody have any ideas on haw to handle this, or a potential solutions?<br></div><div><br></div><div>Thank You!<br></div>