lib/Connection.js
function() {
      var t = this, socket = t.get('socket');
      if (t.socketEvents) {throw new Error('Already connected');}
      t.socketEvents = {};  // key = event name, data = handler

      // Failure events
      t.addEvent('connect_failed', function(){
        t.trigger('error', 'connect failed');
        t.disconnect('connect failed');
      });
      t.addEvent('disconnect', function(){t.disconnect('remote_disconnect');});
      t.addEvent('error', function(reason){
        t.trigger('error', reason);
        t.disconnect('connect error');
      });

      // Inbound probe events
      t.addEvent('probe:connect', t.probeConnect.bind(t));
      t.addEvent('probe:disconnect', t.probeDisconnect.bind(t));
      t.addEvent('probe:control', t.probeControl.bind(t));

      // Connection events
      t.addEvent('connection:ping', function(){socket.emit('connection:pong');});
      t.addEvent('connection:pong', function(){t.trigger('pong');});

      // Connected once remote info is known
      t.addEvent('connection:info', function (info) {
        t.set({
          remoteHostName: info.hostName,
          remoteAppName: info.appName,
          remoteAppInstance: info.appInstance,
          remotePID: info.pid,
          remoteProbeClasses: info.probeClasses,
          remoteGateway: info.gateway,
          remoteFirewall: info.firewall
        });
        t.connecting = false;
        t.connected = true;
        t.trigger('connect');
      });

      // Determine the process id
      var pid = typeof process === 'undefined' ? 1 : process.pid;

      // Determine the app instance
      var appInstance = '' + (typeof process === 'undefined' ? pid : process.env.NODE_APP_INSTANCE || pid);

      // Exchange connection information
      socket.emit('connection:info', {
        hostName:Monitor.getRouter().getHostName(),
        appName:Config.Monitor.appName,
        appInstance: appInstance,
        pid: pid,
        probeClasses: _.keys(Probe.classes),
        gateway:t.get('gateway'),
        firewall:t.get('firewall')
      });
    }
function() {
      var t = this, socket = t.get('socket');
      if (t.socketEvents) {throw new Error('Already connected');}
      t.socketEvents = {};  // key = event name, data = handler

      // Failure events
      t.addEvent('connect_failed', function(){
        t.trigger('error', 'connect failed');
        t.disconnect('connect failed');
      });
      t.addEvent('disconnect', function(){t.disconnect('remote_disconnect');});
      t.addEvent('error', function(reason){
        t.trigger('error', reason);
        t.disconnect('connect error');
      });

      // Inbound probe events
      t.addEvent('probe:connect', t.probeConnect.bind(t));
      t.addEvent('probe:disconnect', t.probeDisconnect.bind(t));
      t.addEvent('probe:control', t.probeControl.bind(t));

      // Connection events
      t.addEvent('connection:ping', function(){socket.emit('connection:pong');});
      t.addEvent('connection:pong', function(){t.trigger('pong');});

      // Connected once remote info is known
      t.addEvent('connection:info', function (info) {
        t.set({
          remoteHostName: info.hostName,
          remoteAppName: info.appName,
          remoteAppInstance: info.appInstance,
          remotePID: info.pid,
          remoteProbeClasses: info.probeClasses,
          remoteGateway: info.gateway,
          remoteFirewall: info.firewall
        });
        t.connecting = false;
        t.connected = true;
        t.trigger('connect');
      });

      // Determine the process id
      var pid = typeof process === 'undefined' ? 1 : process.pid;

      // Determine the app instance
      var appInstance = '' + (typeof process === 'undefined' ? pid : process.env.NODE_APP_INSTANCE || pid);

      // Exchange connection information
      socket.emit('connection:info', {
        hostName:Monitor.getRouter().getHostName(),
        appName:Config.Monitor.appName,
        appInstance: appInstance,
        pid: pid,
        probeClasses: _.keys(Probe.classes),
        gateway:t.get('gateway'),
        firewall:t.get('firewall')
      });
    }
function ( ) { var t = this , socket = t . get ( 'socket' ) ; if ( t . socketEvents ) { throw new Error ( 'Already connected' ) ; } t . socketEvents = { } ; // key = event name, data = handler // Failure events t . addEvent ( 'connect_failed' , function ( ) { t . trigger ( 'error' , 'connect failed' ) ; t . disconnect ( 'connect failed' ) ; } ) ; t . addEvent ( 'disconnect' , function ( ) { t . disconnect ( 'remote_disconnect' ) ; } ) ; t . addEvent ( 'error' , function ( reason ) { t . trigger ( 'error' , reason ) ; t . disconnect ( 'connect error' ) ; } ) ; // Inbound probe events t . addEvent ( 'probe:connect' , t . probeConnect . bind ( t ) ) ; t . addEvent ( 'probe:disconnect' , t . probeDisconnect . bind ( t ) ) ; t . addEvent ( 'probe:control' , t . probeControl . bind ( t ) ) ; // Connection events t . addEvent ( 'connection:ping' , function ( ) { socket . emit ( 'connection:pong' ) ; } ) ; t . addEvent ( 'connection:pong' , function ( ) { t . trigger ( 'pong' ) ; } ) ; // Connected once remote info is known t . addEvent ( 'connection:info' , function ( info ) { t . set ( { remoteHostName : info . hostName , remoteAppName : info . appName , remoteAppInstance : info . appInstance , remotePID : info . pid , remoteProbeClasses : info . probeClasses , remoteGateway : info . gateway , remoteFirewall : info . firewall } ) ; t . connecting = false ; t . connected = true ; t . trigger ( 'connect' ) ; } ) ; // Determine the process id var pid = typeof process === 'undefined' ? 1 : process . pid ; // Determine the app instance var appInstance = '' + ( typeof process === 'undefined' ? pid : process . env . NODE_APP_INSTANCE || pid ) ; // Exchange connection information socket . emit ( 'connection:info' , { hostName : Monitor . getRouter ( ) . getHostName ( ) , appName : Config . Monitor . appName , appInstance : appInstance , pid : pid , probeClasses : _ . keys ( Probe . classes ) , gateway : t . get ( 'gateway' ) , firewall : t . get ( 'firewall' ) } ) ; }
An error has occurred on the connection

This event is triggered when an error occurs on the connection.  Errors
may occur when network is unstable, and can be an indication of impending
disconnection.

@event error
@param err {Object} Reason for the error (from underlying transport)
An error has occurred on the connection