Launch Week Day 1:Rust Support in Socket Is Now Generally Available.Learn More
Socket
Book a DemoInstallSign in
Socket

hms-protocol

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hms-protocol

The protocol stream that hms uses to communicate between servers and clients

latest
Source
npmnpm
Version
1.2.3
Version published
Weekly downloads
3
50%
Maintainers
2
Weekly downloads
 
Created
Source

hms-protocol

The protocol stream that hms uses to communicate between servers and clients

npm install hms-protocol

Build Status

This is mostly only useful for hms

Usage

Simply pipe the stream to and from a source

var protocol = require('hms-protocol');
var net = require('net');

net.createServer(function(stream) {
	var p = protocol();
	stream.pipe(p).pipe(stream);

	p.on('start', function(id, cb) {
		console.log('we received a start for', id);
		cb();
	});
}).listen(10000, function() {
	var p = protocol();
	var stream = net.connect(10000);
	stream.pipe(p).pipe(stream);

	p.start('test', function(err) {
		console.log('start was received?', err);
	});
});

Send messages

The following messages are supported over the protocol

  • p.handshake(opts, cb) send a protocol handhake
  • p.ping(cb) ping to see if remote is alive
  • p.get(id, cb) get information about a service
  • p.add(id, service, cb) add a new service.
  • p.update(id, service, cb) update an existing service
  • p.remove(id, cb) remove a service
  • p.list(cb) list all services
  • p.ps(cb) get process information about all services
  • p.start(id, cb) start a service
  • p.stop(id, cb) stop a service
  • p.restart(id, cb) restart a service
  • p.sync(id, service, cb) sync service state
  • p.subscribe([id], cb) subscribe to service events. omit the id to subscribe to *
  • p.unsubscribe([id], cb) unsubscribe from service events. omit the id to unsubscribe *
  • p.stdout(id, origin, buffer) send a stdout event
  • p.stderr(id, origin, buffer) send a stderr event
  • p.spawn(id, origin, pid) send a process spawn event
  • p.exit(id, origin, code) send a process exit event
  • p.amSubscribing(id) returns true if you are subscribing to id
  • p.peerSubscribing(id) returns true if the peer is subscribing to id

The service message can contain the following

{
	start: 'node .',
	build: 'npm install',
	docks: [
		'dock-id-to-run-at'
	],
	env: {
		FOO: 'bar'
	}
}

Receive messages

Sending any of the above messages will trigger an event of the same for the receiver. I.e. if you do p.start(id, cb) it will result in p.on('start', id, cb) being triggered for the receiver

License

MIT

FAQs

Package last updated on 06 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts