text: const http = require('http');
  const url = require('url');
  const WebSocket = require('ws');
  
  const server = http.createServer();
  const wss1 = new WebSocket.Server({ noServer: true });
  const wss2 = new WebSocket.Server({ noServer: true });
  
  // Broadcast to all.
  function broadcast(ws) {
      ws.broadcast = (function (data) {
          ws.clients.forEach(function each(client) {
              if (client.readyState === WebSocket.OPEN) {
                  client.send(data);
              }
          });
      });
  }
  broadcast(wss1);
  broadcast(wss2);
  
  wss1.on('connection', function connection(ws, req) {
      ws.on('message', function incoming(message) {
          console.log('received: %s', message);
          wss1.broadcast('ok');
      });
  });
  
  wss2.on('connection', function connection(ws, rea) {
      ws.on('message', function incoming(message) {
          console.log('received: %s', message);
      });
  });
  
  server.on('upgrade', function upgrade(request, socket, head) {
      const pathname = url.parse(request.url).pathname;
  
      if (pathname === '/foo') {
          wss1.handleUpgrade(request, socket, head, function done(ws) {
              wss1.emit('connection', ws, request);
          });
      } else if (pathname === '/bar') {
          wss2.handleUpgrade(request, socket, head, function done(ws) {
              wss2.emit('connection', ws, request);
          });
      } else {
          socket.destroy();
      }
  });
  
  server.listen(8080);
  