Initial web socket API.

This PR is to a `websocket` feature branch for later merging into `master`.
Off topic: should we add this API elsewhere? We don't currently.