Created
August 20, 2012 15:23
-
-
Save vishr/3405127 to your computer and use it in GitHub Desktop.
Revisions
-
Vishal Rana renamed this gist
Aug 20, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Vishal Rana created this gist
Aug 20, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script> <script type="text/javascript"> var sock = null; var wsuri = "ws://localhost:3000"; window.onload = function() { sock = new WebSocket(wsuri); sock.onopen = function() { console.log("connected to " + wsuri); } sock.onclose = function(e) { console.log("connection closed (" + e.code + ")"); } sock.onmessage = function(e) { console.log("message received: " + e.data); } } $("#files").live("change", function(e) { $.each(e.target.files, function(i, f) { var chunks = chunkify(f) $.each(chunks, function(i, c) { sock.send(c); }); }); }); function chunkify(file) { var step = 32 * 1024, start = 0, end = step, chunks = []; while (end <= file.size + step) { chunks.push(file.slice(start, end)); start = end; end += step; } return chunks; } </script> </head> <body> <form> <input id="files" type="file" multiple> </form> </body> </html> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ var express = require('express'), routes = require('./routes'), http = require('http'), path = require('path'), WebSocketServer = require("ws").Server; var app = express(); app.configure(function() { app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); }); app.configure('development', function() { app.use(express.errorHandler()); }); app.get('/', routes.index); var server = http.createServer(app).listen(app.get('port'), function() { console.log("Express server listening on port " + app.get('port')); }); var wss = new WebSocketServer({ server: server }); wss.on("connection", function(ws) { var now = Date.now(); ws.on("message", function(data, flags) { var channel; if (flags.binary) { console.log("took: %d", Date.now() - now); now = Date.now(); } }); });