Add test code used to diagnose bug #37.

This commit is contained in:
David Baird
2014-11-13 08:43:07 -05:00
parent 5abf4a78bd
commit 4fe25a880f
4 changed files with 230 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
/*
Prerequisites:
1. Install node.js and npm
2. npm install ws
See also,
http://einaros.github.com/ws/
To run,
node example-server.js
*/
"use strict"; // http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
var WebSocketServer = require('ws').Server;
var http = require('http');
var app = http.createServer();
var server; // assigned by app.listen() below
var wssEchoWithSize = new WebSocketServer({server: app, path: '/echoWithSize'});
wssEchoWithSize.on('connection', function(ws) {
ws.on('message', function(data, flags) {
if (flags.binary) { return; }
ws.send(data.length + '\n' + data);
});
ws.on('close', function() {
});
ws.on('error', function(e) {
});
});
var wssKillServer = new WebSocketServer({server: app, path: '/killServer'});
wssKillServer.on('connection', function(ws) {
ws.on('message', function(data, flags) {
if (flags.binary) { return; }
server.close();
});
ws.on('close', function() {
});
ws.on('error', function(e) {
});
});
var PORT = parseInt(process.env.PORT || '8123');
server = app.listen(PORT);
console.log('Listening on port ' + PORT + '...');