Initial web socket API.

This PR is to a `websocket` feature branch for later merging into `master`.
(I suspect not; the API should probably document the rules)