How to use the nssocket.createServer function in nssocket

To help you get started, we’ve selected a few nssocket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github foreversd / forever / lib / forever / worker.js View on Github external
function findAndStart() {
    self._socket = nssocket.createServer(workerProtocol);
    self._socket.on('listening', function () {
      //
      // `listening` listener doesn't take error as the first parameter
      //
      self.emit('start');
      if (callback) {
        callback(null, self._sockFile);
      }
    });

    self._socket.on('error', function (err) {
      if (err.code === 'EADDRINUSE') {
        return findAndStart();
      }
      else if (callback) {
        callback(err);
github marcelklehr / smokesignal / lib / node.js View on Github external
Node.prototype.start = function() {
  if(this.listening) return
  
  // Set up the server
  this.server = nssocket.createServer(function (socket) {
    this.logger.debug('Incoming Connection from '+socket.socket.remoteAddress+':'+socket.socket.remotePort)
    
    socket.data(['smoke', 'handshake'], this.onHandshake.bind(this, socket))
    socket.data(['smoke', 'peer request'], this.onUnconnectedPeerRequest.bind(this, socket))
    socket.data(['smoke', 'pong'], this.onPong.bind(this, socket))
    
    socket.on('error', function(er) {
      this.logger.error(er)
      socket.destroy()
    }.bind(this))
    
    socket._smokeTimeout = setTimeout(function() {
      socket.destroy()
    }, 5000)
  }.bind(this))
github cardstack / cardstack / packages / hub / docker-container / ember-connection.js View on Github external
constructor({ orchestrator, heartbeat, ready }) {
    this.orchestrator = orchestrator;

    if (heartbeat) {
      this.stopLater = _.debounce(this._stop.bind(this), HUB_HEARTBEAT_TIMEOUT);
    }

    let that = this;

    this._server = nssocket.createServer(async function(socket) {
      log.info('Connection established from ember-cli');

      // Docker does some weird stuff for containers with published ports
      // before they start actually listening on the port. Long story short,
      // we need a handshake when we first establish a connection.
      socket.data('hand', function() {
        socket.send('shake');
      });

      // Ember-cli may shut us down manually.
      socket.data('shutdown', function() {
        log.info('Received shutdown message from ember-cli');
        orchestrator.stop();
      });

      if (heartbeat) {
github keymetrics / pmx / test / vxx.e2e.mocha.js View on Github external
function listenRev(cb) {
  var listener_server = require('nssocket').createServer(function(_socket) {
  });

  listener_server.listen(4322, '0.0.0.0', function() {
    console.log('Reverse interact online');
    cb();
  });
}
github snupa / node-queuefy / lib / server.js View on Github external
server.prototype.listen = function Listen(callback) {
	var self = this;
	this.connection = nssocket.createServer(function(socket) {
		var onError = function OnError(e) {
			socket._connected = false;
			socket.destroy();
		};
		socket.on('error', onError);
		socket._connected = true;
		self.bindSocket(socket);
	});
	this.connection.on('error', function(e) {
		self.emit('error', e);
	});
	self.connection.listen(self.config.port, self.config.host, function() {
		if(typeof callback == 'function') callback.call(self);
	});
	return this;
};
github patr0nus / n2n / lib / seed.js View on Github external
function Seed() {
    events.EventEmitter.call(this);

    this.nodes = {};
    this.sockets = {};
    
    this.nsserver = nssocket.createServer(function (socket) {
      var nodeId = uuid.v1();
      var nodeInfo = {
        id: nodeId
      }
    
      this.sockets[nodeId] = socket;
      this.nodes[nodeId] = nodeInfo;
      socket.send('id', nodeId);
    
      socket.on('close', function (data) {
        delete this.nodes[nodeId];
        delete this.sockets[nodeId];
        this.broadcast('node::offline', nodeId);
      }.bind(this));
      
      socket.on('error', function (err) {

nssocket

An elegant way to define lightweight protocols on-top of TCP/TLS sockets in node.js

MIT
Latest version published 9 years ago

Package Health Score

74 / 100
Full package analysis