'use strict';

const SocketServer = require('net').Server,
      EventEmitter = require('events'),
      handler = require('./handler');

/* lib/server.js
 * Server object.
 * * */

// Export server.
module.exports = Server;

// The server object, Rela.
function Server(opts){
  // Shorthand, no "new" required.
  if (!(this instanceof Server))
    return new Server(...arguments);

  if (typeof opts !== 'object')
    opts = {};

  this.clients = opts.dummies || [];
  this.server = opts.server || new SocketServer(handler.bind(this));
}

// Add EventEmitter functionality to all Rela instances.
Server.prototype = new EventEmitter();

// Shorthand listen.
Server.prototype.listen = function(){
  this.server.listen(...arguments);
};

@@ -98,23 +98,61 @@
 ,%0A      
-handler
+Client = require('./client'),%0A      handshake
  = requi
@@ -161,19 +161,21 @@
 ('./hand
-ler
+shake
 ');%0A%0A/* 
@@ -501,16 +501,17 @@
  %7C%7C %5B%5D;%0A
+%0A
   this.s
@@ -554,26 +554,184 @@
 ver(
-handler.bind(this)
+socket =%3E %7B%0A    let client = new Client(socket);%0A    this.clients.push(client);%0A    this.emit('connection', client);%0A%0A    client._socket.on('data', handshake.bind(client));%0A  %7D
 );%0A%7D

Move handling into lib/server.js