How to use the nssocket.NsSocket 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 snupa / node-queuefy / lib / worker.js View on Github external
worker.prototype.connect = function Connect(callback) {
	var self = this;
	this.connection = new nssocket.NsSocket();
	this.connection.on('error', function(e) {
		self._connected = false;
		self.connection.destroy();
		// Any callbacks expecting result will be called with error
		for(var callback_id in self.CALLBACKS) {
			self.CALLBACKS[callback_id].call(self, e, null);
			delete self.CALLBACKS[callback_id];
		}
		self.emit('disconnect');
		setTimeout(function() {
			self.connect();
		}, 100);
	});
	this.connection.connect(this.config.port, this.config.host, function() {
		self._connected = true;
		Bind.call(self);
github cardstack / cardstack / packages / hub / docker-host / hub-connection.js View on Github external
async function _connect() {
  let socket = new nssocket.NsSocket();
  socket.connect(6785);

  return new Promise(function(resolve, reject) {
    log.trace("Attempting to connect to the hub's heartbeat port");

    async function onClose(err) {
      // When a container is starting up and hasn't yet internally
      // started listening on a port, Docker trolls us by accepting the
      // connection, but then immediately closing the connection.
      // So, if it was closed with no error, just try again.
      if (!err) {
        await timeout(50);
        resolve(_connect());
      }
    }
github foreversd / forever / lib / forever.js View on Github external
function sendAction(proc, next) {
    var socket = new nssocket.NsSocket();

    function onMessage(data) {
      //
      // Cleanup the socket.
      //
      socket.undata([action, 'ok'],    onMessage);
      socket.undata([action, 'error'], onMessage);
      socket.end();

      //
      // Messages are only sent back from error cases. The event
      // calling context is available from `nssocket`.
      //
      var message = data && data.message,
          type    = this.event.slice().pop();
github patr0nus / n2n / lib / node.js View on Github external
function Node(port) {
    events.EventEmitter.call(this);
    this.nsclient = new nssocket.NsSocket();
    this.nodes = {};
    this.sortedIds = [];
    
    var thisNode = this;
    
    this.nsclient.data('id', function (id) {
      this.id = id;
      getPublicIP(function (ip) {
        if (ip) {
          this.nsclient.send('ip', ip, port);
        }
        else {
          this.nsclient.send('ip');
        }
      }.bind(this));
    }.bind(this));
github marcelklehr / smokesignal / lib / node.js View on Github external
Node.prototype.addPeer = function(address, port) {
  this.logger.trace('Trying to add peer at "'+address+':'+port+'"')
  var socket = new nssocket.NsSocket();
  socket.on('error', function(e) {
    this.logger.error('An error occured while establishing connection to new peer at "'+address+':'+port+'"', e)
  }.bind(this))
  socket.connect(port, address, function() {
    this.logger.trace('sending handshake to "'+address+':'+port+'"')
    socket.send(['smoke', 'handshake'], {id: this.id})
    socket.data(['smoke', 'handshake ack'], this.onHandshakeAck.bind(this, socket))
  }.bind(this))
}
github winstonjs / winston / lib / winston / transports / nssocket.js View on Github external
var NsSocket = exports.Nssocket = function (options) {
  options = options || {};

  this.name = 'nssocket';
  this.logEvent = options.logEvent || ['log'];

  this.socket = new nssocket.NsSocket(options.socket || {
    reconnect: true
  });

  this.socket.connect(options.host, options.port);
};
github ezpaarse-project / ezpaarse / node_modules / forever / lib / forever.js View on Github external
function sendAction(proc, next) {
    var socket = new nssocket.NsSocket();

    socket.connect(proc.socket, function (err) {
      if (err) {
        next(err);
      }

      socket.dataOnce([action, 'ok'], function (data) {
        next();
        socket.end();
      });

      socket.send([action]);
    });

    socket.on('error', function (err) {
      next(err);
github marcelklehr / smokesignal / lib / node.js View on Github external
this.options.seeds.forEach(function(seed) {
      if(seed.port == this.options.port && seed.address == this.options.address) return this.logger.info('I seem to be a seed')
      this.logger.info('Trying to enter network through seed "'+seed.address+':'+seed.port+'"')

      var socket = new nssocket.NsSocket();
      socket.on('error', function(e) {
        this.logger.error('An error occured while trying to enter netork through seed "'+seed.address+':'+seed.port+'"', e)
      }.bind(this))
      socket.connect(seed.port, seed.address, function() {
        socket.send(['smoke', 'peer request'], {
          id: this.id
          , remoteAddress: this.options.address
          , remotePort: this.options.port
          })
      }.bind(this))
  
    }.bind(this))
  }

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