// WebSocket vs. Socket.IO example - common backend - from:
// https://github.com/rsp/node-websocket-vs-socket.io
// Copyright (c) 2015, 2016 Rafał Pocztarski
// Released under MIT License (Expat) - see:
// https://github.com/rsp/node-websocket-vs-socket.io/blob/master/LICENSE.md

var express = require('express');

// WebSocket:
var ws = {app: express(), pre: "websocket app: "};
ws.log = m => console.error(ws.pre+m);
ws.ws = require('express-ws')(ws.app);
ws.app.get('/', (req, res) => {
  ws.log('express connection - sending html');
  res.sendFile(__dirname + '/ws.html');
});
ws.app.ws('/', (s, req) => {
  ws.log('websocket connection');
  for (var t = 0; t < 3; t++)
    setTimeout(() => {
      ws.log('sending message to client');
      s.send(ws.pre+'message from server');
    }, 1000*t);
});
ws.app.listen(3001, () =>
  ws.log('listening on http://localhost:3001/'));
ws.log('starting server');

// Socket.IO:
var si = {app: express(), pre: "socket.io app: "};
si.log = m => console.error(si.pre+m);
si.http = require('http').Server(si.app);
si.io = require('socket.io')(si.http);
si.app.get('/', (req, res) => {
  si.log('express connection - sending html');
  res.sendFile(__dirname + '/si.html');
});
si.io.on('connection', s => {
  si.log('socket.io connection');
  for (var t = 0; t < 3; t++)
    setTimeout(() => {
      si.log('sending message to client');
      s.emit('message', si.pre+'message from server');
    }, 1000*t);
});
si.http.listen(3002, () =>
  si.log('listening on http://localhost:3002/'));
si.log('starting server');

@@ -305,24 +305,108 @@
 'express');%0A
+var log = function (m) %7B%0A  console.error(new Date().toISOString()+' '+this.pre+m);%0A%7D
 %0A// WebSocke
@@ -460,48 +460,19 @@
 p: %22
-%7D;%0Aws.log = m =%3E console.error(ws.pre+m)
+, log: log%7D
 ;%0Aws
@@ -670,16 +670,25 @@
 ws.log('
+incoming 
 websocke
@@ -1033,48 +1033,19 @@
 p: %22
-%7D;%0Asi.log = m =%3E console.error(si.pre+m)
+, log: log%7D
 ;%0Asi
@@ -1286,16 +1286,25 @@
 si.log('
+incoming 
 socket.i

refactor ws-vs-si.js