net = require( 'net' );

var clients = [];

var socket = net.createServer( function ( socket ) {
  socket.name = socket.remoteAddress + ":" + socket.remotePort;
  socket.id = clients.length;
  clients.push( socket );
  console.log( "connected to client " + socket.name );

  var clientID = new Buffer( [ 255, clients.length - 1 ] );
  socket.write( clientID );
  var clientJoinMsg = new Buffer( [ 254, clients.length - 1 ] );
  clients.forEach( function( client ) {
    if ( client == socket ) return;
    client.write( clientJoinMsg );
  } );

  socket.on( 'data', function( data ) {
    console.log( data );
    relay( data, socket );
  } );

  socket.on( 'end', function() {
    clients.splice( clients.indexOf( socket ), 1 );
    // relay leave event
    console.log( "client " + socket.name + " left the game." );
  } );

  function relay( data, sender ) {
    clients.forEach( function( client ) {
      if ( client == sender ) return;
      var posID = new Buffer( [ 253, sender.id ] );
      client.write( posID );
      client.write( data );
    } );
  }
} ).listen( process.env.PORT || 5000, null );

@@ -360,29 +360,26 @@
 ;%0A  var 
-clien
+socke
 tJoin
-Msg
  = new B
@@ -443,32 +443,45 @@
 function( client
+, clientIndex
  ) %7B%0A    if ( cl
@@ -527,21 +527,105 @@
 te( 
-clientJoinMsg
+socketJoin );%0A    var clientAdd = new Buffer( %5B 254, clientIndex %5D );%0A    socket.write( clientAdd
  );%0A

send current players to new player on join so first player exist on on second player's machine