Skip to content

Instantly share code, notes, and snippets.

@srohde
Created November 15, 2013 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srohde/7477792 to your computer and use it in GitHub Desktop.
Save srohde/7477792 to your computer and use it in GitHub Desktop.
proof of concept node.js socket implementation
WebSocketServer = require('ws').Server
websocket = null
wss = new WebSocketServer
server: server
console.log('websocket server created')
clients = {}
wss.on 'connection', (ws) ->
websocket = ws
ws.on 'message', (message) ->
console.log "on message " + message
msg = JSON.parse message
if msg.id?
clients[msg.id] = ws
console.log "got id " + msg.id
else if msg.client? and msg.action?
console.log "message: #{JSON.stringify(message)}"
for client of clients
console.log "client " + client
clients[client].send JSON.stringify({action:msg.action}), ->
else
console.log "warn: unkown ws: #{message}"
console.log('websocket connection open')
ws.on 'close', ->
console.log('websocket connection close')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment