SocketStream: A WebSocket Web Framework
Posted by Dion Almaer about a year ago on event node realtime redis websocket
After discussing the nice match of redis and a framework such as Socket.IO, I was shown SocketStream from Owen Barnes.
SocketStream is a new full stack web framework built around the Single-page Application paradigm. It embraces websockets, in-memory datastores (Redis), and client-side rendering to provide an ultra-responsive experience that will amaze your users.
Project status: Highly experimental but usable. Improving almost every day.
SocketStream automatically compresses and minifies all the static HTML, CSS and client-side code your app will ever need and sends this through the first time a user visits your site.
From then on all application data is sent and received as serialized JSON objects over a websocket (or ‘flashsocket’) tunnel, instantly established when the client connects and automatically re-established if broken.
All this means no more connection latency, HTTP header overhead, or clunky Ajax calls. Just true bi-directional, asynchronous, ‘streaming’ communication between client and server.
There is an early tutorial, and for a quick look at what it feels to write event based code see this:
// Server Code
exports.actions =
lookup: (coords_from_browser, cb) ->
host = 'maps.googleapis.com'
r = coords_from_browser.coords
http = require('http')
google = http.createClient(80, host)
google.on 'error', (e) -> console.error "Unable to connect to #{host}"
request = google.request 'GET', "/maps/api/geocode/json?sensor=true&latlng=#{r.latitude},#{r.longitude}"
request.end()
request.on 'error', (e) -> console.error "Unable to parse response from #{host}"
request.on 'response', (response) => parseResponse(response, cb)
parseResponse = (response, cb) -> # note: private methods are written outside of exports.actions
output = ''
response.setEncoding('utf8')
response.on 'data', (chunk) -> output += chunk
response.on 'end', ->
j = JSON.parse(output)
result = j.results[0]
cb(result)
// Client Code
# Note: the SS.client.app.init() method automatically gets called once the socket is established and the session is ready
exports.init = ->
SS.client.geocode.determineLocation()