I didn’t bother with the ping/pong stuff - it’s not needed for my app. I implemented all the actual protocol stuff from the RFC except for the FIN bit, which is for fragmentation so a message could be split into more than one chunk to avoid monopolising the channel. Doesn’t affect me as there’s only one HTMLViewer client within the app. I do check for FIN, however, and error that packet if seen. I’ve never yet seen it set, though.
Of course, if you have two entities using a channel to send each other packets, the receiver will want to know what action it’s supposed to take regarding what it’s just received. So I assign the first byte as a Command byte with a code so each side knows what to do. The Server has a work queue, and work items can be queued to it either from the HTMLViewer, or from some other thread within the Xojo side (the WebSocket server runs as a thread).
Edit: I meant to add that the Command byte notion is built in not just to the server but to the DataAvailable event handler too.