Responsible for listening to events from Socket.io, and updating controller properties that
subscribe to those events.

@method _listen
@return {void}
@private
322642
function _listen() {

            var controllers     = $ember.get(this, 'controllers'),
                getController   = Ember.run.bind(this, this._getController),
                events          = [],
                module          = this,
                respond         = function respond() {
                    var eventData = Array.prototype.slice.call(arguments);
                    module._update.call(module, this, eventData);
                };

            controllers.forEach(function controllerIteration(controllerName) {

                // Fetch the controller if it's valid.
                var controller  = getController(controllerName),
                    eventNames  = controller[this.NAMESPACE];

                if (controller) {

                    // Invoke the `connect` method if it has been defined on this controller.
                    if (typeof controller[this.NAMESPACE] === 'object' && typeof controller[this.NAMESPACE].connect === 'function') {
                        controller[this.NAMESPACE].connect.apply(controller);
                    }

                    // Iterate over each event defined in the controller's `sockets` hash, so that we can
                    // keep an eye open for them.
                    for (var eventName in eventNames) {

                        if (eventNames.hasOwnProperty(eventName)) {

                            if (events.indexOf(eventName) !== -1) {
                                // Don't observe this event if we're already observing it.
                                continue;
                            }

                            // Push the event so we don't listen for it twice.
                            events.push(eventName);

                            // Check to ensure the event was not previously registered due to a reconnect
                            if (!(eventName in $ember.get(module, 'socket')._callbacks)) {

                                // ...And finally we can register the event to listen for it.
                                $ember.get(module, 'socket').on(eventName, respond.bind(eventName));

                            }

                        }

                    }

                }

            }, this);

        }
1006393
function init() {
      var _this = this;

      this._shouldSyncFromOpts = true;
      this.on('update', function () {
        if (_this._shouldSyncFromOpts) _this.trigger('sync');
        _this._shouldSyncFromOpts = true;
      });
    }
245867
def subscribe(*args, &block)
      @mutex.synchronize do
        listener = Listener.new(*args)
        listener.on_delivery(&block)
        @listeners << listener
      end
    end
962084
def listen(self):
        ''''''
        for message in Listener.listen(self):
            logger.debug('Message: %s', message)
            # Strip off the 'namespace' from the channel
            channel = message['channel'][len(self.namespace):]
            func = self._callbacks.get(channel)
            if func:
                func(message['data'])
772246
function Listener() {
		// setup abstract layer
		core.ListenerAbstract.apply(this, arguments);

		var self = this;

		// in case the process die, the connection will be severed
		this.object.on('exit', function () {
			if (self.online === true) {
				this.emit('close');
			}
		});

		process.nextTick(function () {
			// setup a new connection with the object
			self.emit('listening');

			// setup a new connection with the object
			self.emit('connection', self.object);
		});
	}
270265
function() {
      io = io.listen(app);
      io.set("log level", 1);
      io.sockets.on("connection", function(socket) {
        connections += 1;
        console.log("   info  -".cyan, ("new connection. Connections: " + connections).yellow);

        socket.on("disconnect", function() {
          connections -= 1;
          console.log("   info  -".cyan, ("connection closed. Connections: " + connections).yellow);
        });

        socket.on("iframe-loaded", function(data) {
          urlData[data.id].counter--;
          console.log("   info  -".cyan, ("client sends event iframe-loaded").yellow, JSON.stringify(data));
        });
      });
    }
1224585
public function listen(): void
    {
        $this->socket->listen();
        $this->resources[$this->socket->getResourceId()] = $this->socket->getResource();
    }
1150227
function Listener() {
		// setup abstract layer
		core.ListenerAbstract.apply(this, arguments);

		// parse the argument
		if (!(this.object instanceof net.Server)) {

			// create a new TCP server
			if (typeof this.object === 'number' || typeof this.object === 'string') {
				this.object = net.createServer().listen(this.object);
			} else {
				this.object = net.createServer().listen(this.object.port, this.object.host);
			}

			this.object.on('listening', this.emit.bind(this, 'listening'));
		} else {
			this.emit('listening');
		}

		// relay errors
		this.object.on('error', this.emit.bind(this, 'error'));

		// relay the close event
		this.object.on('close', this.emit.bind(this, 'close'));

		var self = this;
		// when a remote has connected to this server, this TCP event will emit
		this.object.on('connection', function (socket) {

			// we will emit the connection event to create a new communication object
			// the socket argument set here will be this.object in the new communication object
			self.emit('connection', socket);
		});
	}
728620
function Messages () {
  var self = this;

  if (!(this instanceof Messages)) return new Messages();

  events.EventEmitter.call(this);

  debug('new messages');

  /**
   * When a socket is accepted
   *
   * @param {object} socket
   */

  this.onConnection = function (socket) {

    debug('on connection %s', socket.id);

    /**
     * This is used to add listeners to sockets when the Messages.prototype.action()
     * method is invoked
     *
     * @param {string} name
     */

    function onAction (name) {
      debug('on action %s', name);
      if (socket.listeners(name).indexOf(self.onMessage) < 0) {
        socket.on(name, function () {
          debug('socket on %s', name);
          var args = Array.prototype.slice.call(arguments);
          self.onMessage(socket, [name].concat(args));
        });
      }
    }
   
    self.on('action', onAction);

    /*
     * take the current actions and set up handlers for them
     */

    if (self.actions()) {
      self.actions().forEach(onAction);
    }


    /*
     * when we disconnect we want to remove the handlers and the onAction
     * method
     */

    socket.on('disconnect', function () {
      debug('on disconnect %s', socket.id);
      self.removeListener('action', onAction);
      self.actions().forEach(function (name) {
        debug('removing listeners for %s', name);
        socket.removeAllListeners(name);
        debug('listener count %s for %s', socket.listeners(name).length, name);
      });
    });

  };

  /*
   * Called when we receive data from the socket
   * It will build up the actor, target, and content
   * to produce a json object that will be published
   * onto an publisher / event emitter
   */

  this.onMessage = function (socket, args) {
    debug('on message %s', socket.id);
    args = args || [];
    if (!args.length) return;
    var message, isMessage = false;
    if (args.length === 2 && args[1] && args[1].isMessage) {
      isMessage = true;
      message = Message(args[1]);  
    }
    else {
      message = Message();
    }
    message.action(args.shift());
    self.actor(socket, function (err, actor) {
      debug('on actor %s, %s', socket.id, actor);
      if (err) {
        return self.emit('error', err, socket, args);
      }
      message.actor(actor);
      self.target(socket, args, function (err, target) {
        debug('on target %s, %s', socket.id, actor);
        if (err) {
          return self.emit('error', err, socket, args);
        }
        message.target(target);
        if (!isMessage) message.content(args);
        self.emit('message', message, socket);
      });
    });
  };

  /*
   * the middleware fucntion we attach to socket.io. It looks for events and if
   * we have auto propagation turned on it will trigger events that are *not*
   * in the current action set.
   */

  this.middleware = function (socket, next) {
    debug('middleware invoked on socket %s', socket.id);
    socket.onevent = self.onSocketEvent;
    next();
  };

  /*
   * The function we override the onevent with.
   */

  // TODO lets use socket.io-events

  this.onSocketEvent = function(packet) {
    debug('on socket event for socket %s', this.id);
    var args = packet.data || [];

    if (null != packet.id) {
      args.push(this.ack(packet.id));
    }

    if (this.listeners(args[0]).length) {
      events.EventEmitter.prototype.emit.apply(this, args);
    }
    else if (self.autoPropagate()) {
      self.onMessage(this, args);
    }

  };

  this.setMaxListeners(0);
}
360704
function(object, events) {
        if (!object.__isInterfaceImplemented('events')) {
            object.__implementInterface('events', this.interface);
        }

        object.__initEvents();

        _.each(events, function(eventListeners, eventName) {
            _.each(eventListeners, function(listener, listenerName) {
                object.__addEventListener(eventName, listenerName, listener);
            });
        });
    }
310163
function() {
  EventEmitter.call(this);
  this.httpServer = new HttpServer();

  var self = this;
  this.wsServer = new WebSocketServer({server: this.httpServer});

  this.wsServer.on('connection', function(socket) {
    // emit socket to outside
    self.emit('connection', socket);
  });

  this.state = ST_STARTED;
}
1066131
def set_event_handler(self, event_handler):
        '''
        
        '''
        assert not self._run_io_loop_sync

        if not self.cpub:
            self.connect_pub()

        self.subscriber.callbacks.add(event_handler)
        if not self.subscriber.reading:
            # This will handle reconnects
            return self.subscriber.read_async()
214389
def subscribe(self, event, handler):
        
        self._handlers.sync_handlers[event].append(handler)
567440
public function listen()
    {
        if (defined('LARAVEL_START')) {
            $this->start(static::REQUEST_TIMER, LARAVEL_START);
        }

        $this->dispatcher->listen(StartProfiling::class, function (StartProfiling $event) {
            $this->start($event->name);
        });

        $this->dispatcher->listen(StopProfiling::class, function (StopProfiling $event) {
            $this->stop($event->name);
        });
    }
450597
def listen(*events)
      events.each do |event|
        EVENTS.include?(event) or
          raise ArgumentError, "invalid event: #{event.inspect}"
      end
      @actor << [ "LISTEN", *events ]
    end
1246732
def listen(self):
        

        # Make sure we're in server mode
        if self.mode and self.mode != 'server':
            raise ValueError("%s is not in server mode" %
                             self.__class__.__name__)
        self.mode = 'server'

        # Obtain a listening socket
        serv = _create_server(self.host, self.port)

        # If we have too many errors, we want to bail out
        err_thresh = 0
        while True:
            # Accept a connection
            try:
                sock, addr = serv.accept()
            except Exception as exc:
                err_thresh += 1
                if err_thresh >= self.max_err_thresh:
                    LOG.exception("Too many errors accepting "
                                  "connections: %s" % str(exc))
                    break
                continue  # Pragma: nocover

            # Decrement error count on successful connections
            err_thresh = max(err_thresh - 1, 0)

            # Log the connection attempt
            LOG.info("Accepted connection from %s port %s" %
                     (addr[0], addr[1]))

            # And handle the connection
            eventlet.spawn_n(self.serve, self.connection_class(sock), addr)

        # Close the listening socket
        with utils.ignore_except():
            serv.close()
1202346
def subscribe(caller = nil, &block)
      if block_given?
        notify_when = block.call(state)
        @listeners << { obj: block.binding.receiver, notify_when: notify_when }
      else
        @listeners << { obj: caller }
      end
    end