Skip to content
Browse files

Added logging on disconnect, specificed websocket 1.0.3

  • Loading branch information...
1 parent 02d99e9 commit 787f290611941c5450c8f93df8a01f460cf204f1 @jawj committed Jan 24, 2012
Showing with 33 additions and 5 deletions.
  1. +0 −1 TODO
  2. +21 −0 deploy/INSTALL.txt
  3. +11 −3 deploy/forwarding.coffee
  4. +1 −1 deploy/package.json
View
1 TODO
@@ -1,4 +1,3 @@
-Refactor node.js script + package.json + index.html + AWS recipe to own folder (deploy)
Node.js script to emit client count on disconnect (as well as reconnect), and client IP too on connect
Free/new AWS account w/ CASA details (or a limited-time 512MB Linode?)
Python script to reconnect on disconnection
View
21 deploy/INSTALL.txt
@@ -1,3 +1,24 @@
# Ubuntu 11.10 EC2 micro instance
+ssh -i ~/.ssh/ucl-aws-key.pem ubuntu@ec2-176-34-211-74.eu-west-1.compute.amazonaws.com
+
+sudo add-apt-repository ppa:chris-lea/node.js
+sudo aptitude update
+
+sudo aptitude install nodejs npm htop
+
+sudo aptitude safe-upgrade
+sudo reboot
+
+
+mkdir wskinect
+cd wskinect
+
+wget https://github.com/jawj/websocket-kinect/raw/master/deploy/forwarding.coffee \
+ https://github.com/jawj/websocket-kinect/raw/master/deploy/package.json \
+ https://github.com/jawj/websocket-kinect/raw/master/deploy/index.html
+
+npm install
+
+
View
14 deploy/forwarding.coffee
@@ -24,12 +24,20 @@ else
httpServer.listen(port)
wsServer = new WebSocketServer(httpServer: httpServer, autoAcceptConnections: false)
+log = (s) -> console.log "#{new Date()} - clients: #{wsServer.connections.length} - #{s}"
+
wsServer.on 'request', (request) ->
+ if wsServer.connections.length > 3000
+ log "rejected connection"
+ request.reject()
+ return
connection = request.accept(null, request.origin)
- console.log "clients: #{wsServer.connections.length}"
+ log "connected: #{connection.remoteAddress}"
if connection.remoteAddress is sendingAddress
connection.on 'message', (message) ->
for c in wsServer.connections
- continue if c is connection # don't send back to the sender
- continue unless c.socket.bufferSize is 0 or https # minimal buffering for slow connections (doesn't work with SSL)
+ continue if c is connection # don't send back to the sender
+ continue unless https or c.socket.bufferSize < 100000 # minimal buffering for slow connections (doesn't work with SSL)
c.sendBytes(message.binaryData)
+ connection.on 'close', (reasonCode, description) ->
+ log "disconnected: #{connection.remoteAddress}"
View
2 deploy/package.json
@@ -1,3 +1,3 @@
{ "name": "websocket-kinect"
, "version": "0.1.0"
-, "dependencies": { "websocket": "~1", "coffee-script": "~1" } }
+, "dependencies": { "websocket": "1.0.3", "coffee-script": "~1" } } /* 1.0.4, with UTF8 validation, won't install */

0 comments on commit 787f290

Please sign in to comment.
Something went wrong with that request. Please try again.