To add to the above, I can suggest you might do well to experiment with some event programming on your local machine, without websockets at all, to clarify the main concepts of this style of programming. See 'man anyevent' for examples. You can set up a watcher for each type of event you want to act on.