callback-websocket – creating RESTful services over a WebSocket
Some time ago I started a side project where pushing data to users as fast as possible was a major requirement. Being easily accessible (i.e. not separataly installable) was another, so naturally, I thought this is the time to check out WebSockets.
The trouble of multiple connections
It started off great, I saw that at least two latest versions of most common (desktop) web browsers supported them, Java had a stable WebSockets API etc. But as I cracked on coding, I saw that I was using my fast full-duplex communications channel only for pushing data from the server to the client. For every client side request I still relied on the good old AJAX querying my JAX-RS endpoints.
I began wondering if there was some way to channel all of my communications through the existing WebSocket, as it seemed pointless to create additional connections to my server. As I began poking around I found this cool AngularJS WebSocket service example. The trouble was, that I had no way to intelligently handle these requests on the server.
Continue reading »