Created
November 15, 2013 01:44
-
-
Save srohde/7477792 to your computer and use it in GitHub Desktop.
proof of concept node.js socket implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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