WebSockets?

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.

Well, using Kem’s WS Class, I can connect but the rest of it I can’t figure out. Not able to see any of the messages that are coming back from the server.

All the SD seems to need is ws.connect, ws.write and to handle the on.connect, on.close and on.message events.

Is there a simpler WS Class than Kem’s?

I dont know of any others :man_shrugging:

1 Like

Got it figured out. Trial and error.
Now just need to slim it down.

I just dug out my WebSocket test project and brought it up to date. It has an HTMLViewer and loads some html into it. I think all requests for someone to do something are initiated from the Xojo side but it’s simple enough to have the javascript in the Viewer send a request to the Xojo side to do something.

If anyone’s interested send me a message with an email and I’ll zip it up and send it. It includes the Websocket code (which is most of it, in fact).