Ben's blog

ramblings from cyberspace

I've been somewhat busy with other things on the weekend but today I've returned to work some more on WS2HTTP, and by now things actually work pretty well. It's also a lot less complicated than anticipated (the entire node.js server is ~150 loc).

So now I'm working on the examples, cleaning up the code and especially thinking about the API/architecture to make sure it's actually as simple as possible, and by design sidesteps a lot of problems.

I suppose the client to server part should be quite clear by now, I've pretty much implemented the design as initially though up. The sending part has some minor tweaks, mainly regarding "routing". In order to send a message from server to client the user code needs to do a POST request to the ws2http server, so far so good. Now there are basically 2 ways in which we limit who receives the message.

  1. Send a message to specific ID's, this is probably the most boring one. We can set the id field, and thereby send the message only to these particular sockets. If ws2http can't find a socket it'll trigget an "ERROR" subsequent event which hopefully removes that connection from storage.

  2. Send a message to a URL: ws2http accepts every url and stores it for each connection, we can then send a message to everyone connected to a particular url, this also includes the search parameters, so we can implement chat rooms for example super easily. Additionally there is a field notTo where we can pass a comma separated list of sockets that shouldn't receive that particular message, probably most useful so the sender doesn't receive their own message.

This seems pretty simple and works quite well for the simple chat room example, I'll try and come up with more examples that might unearth limitations in the API. Another part that still needs some thinking is how to configure everything. I'd like ws2http to have the fewest amount of knobs possible, but there probably needs to be a way to specify which endpoint should be informed about an event, mainly based on path and hostname.