var Client  = require('./udp_client').Client;
var Message = require("./message").Message;

var _     = require('underscore');
var dgram = require('dgram');

var handleNewMessage = function(buffer, rinfo) {
  var client = this.clientFor({address: rinfo.address, port: rinfo.port});

  if(!_.include(this.clients, client)) {
    this.clients.push(client);
    this.emit("newClient", client);
  }

  var messageContent = buffer.toString().trim();
  var message = new Message(client, messageContent);
  this.emit("message", message, client);
};

var Server = function(address, port) {
  this.port    = port    || 12345;
  this.address = address || "0.0.0.0";
  this.clients = [];

  this.socket.bind(this.port, this.address);
  this.socket.on("message", handleNewMessage.bind(this));
};

Server.prototype = {
  get socket() {
    this._socket = this._socket || dgram.createSocket("udp4");
    return this._socket;
  },

  clientFor: _.memoize(function(rinfo) {
    return new Client(rinfo.address, rinfo.port);
  }, JSON.stringify)
};
var EventEmitter = require("events").EventEmitter;
_.extend(Server.prototype, EventEmitter.prototype);

exports.Server = Server;

@@ -92,13 +92,13 @@
 var 
-_    
+dgram
  = r
@@ -109,49 +109,94 @@
 re('
-underscore');%0Avar dgram = require('dgram'
+dgram');%0Avar EventEmitter = require(%22events%22).EventEmitter;%0Avar util  = require(%22util%22
 );%0A%0A
@@ -324,121 +324,8 @@
 );%0A%0A
-  if(!_.include(this.clients, client)) %7B%0A    this.clients.push(client);%0A    this.emit(%22newClient%22, client);%0A  %7D%0A%0A
   va
@@ -467,16 +467,17 @@
 t);%0A%7D;%0A%0A
+%0A
 var Serv
@@ -507,16 +507,61 @@
 port) %7B%0A
+  this.socket  = dgram.createSocket(%22udp4%22);%0A
   this.p
@@ -629,29 +629,8 @@
 .0%22;
-%0A  this.clients = %5B%5D;
 %0A%0A  
@@ -734,361 +734,361 @@
 ));%0A
-%7D;%0A%0AServer.prototype = %7B%0A  get socket() %7B%0A    this._socket = this._socket %7C%7C dgram.createSocket(%22udp4%22);%0A    return this._socket;%0A  %7D,%0A%0A  clientFor: _.memoize(function(rinfo) %7B%0A    return new Client(rinfo.address, rinfo.port);%0A  %7D, JSON.stringify)%0A%7D;%0Avar EventEmitter = require(%22events%22).EventEmitter;%0A_.extend(Server.prototype, EventEmitter.prototype);
+%0A  this._clients = %7B%7D;%0A%7D;%0Autil.inherits(Server, EventEmitter);%0A%0A%0AServer.prototype.clientFor = function(rinfo) %7B%0A  var key = %22__%22 + JSON.stringify(rinfo);%0A%0A  var client;%0A  if(this._clients.hasOwnProperty(key)) %7B%0A    client = this._clients%5Bkey%5D;%0A  %7D else %7B%0A    client = this._clients%5Bkey%5D = new Client(rinfo.address, rinfo.port);%0A  %7D%0A%0A  return client;%0A%7D;%0A
 %0A%0Aex

Remove dependency on underscore