Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

hprotocol

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hprotocol

Streaming human readable command protocol

Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
25
733.33%
Maintainers
1
Weekly downloads
 
Created
Source

hprotocol

Streaming human readable command protocol

npm install hprotocol

build status

What does it do?

hprotocol is a redis like protocol that its easy to parse both for programs and human beings. As an example lets echo a value

var hprotocol = require('hprotocol');
var net = require('net');

net.createServer(function(socket) {
	var protocol = hprotocol();

	client.on('message', function(cmd, args, callback) {
		// listen for the echo command
		if (cmd === 'echo') return callback(null, args);
		callback(new Error('unknown command'));
	});

	// setup the pipe chain
	socket.pipe(protocol).pipe(socket);
}).listen(9999);

Open a new termainal and try interfacing with the server.

$ nc localhost 9999 # create a socket to the server
$ echo test         # send a echo command
$ > test            # this is the reply from the server

Similary you can interface with the server using node:

var protocol = hprotocol(); // using the same protocol as above
var socket = net.connect(9999, 'localhost');

socket.pipe(protocol).pipe(socket);

protocol.send('echo', ['test'], function(err, value) {
	console.log(value); // prints ['test']
});

Protocol syntax

All messages are seperated by newlines and arguments are seperated by whitespace.

command arg1 arg2 ...

A response starts with > and error responses start with !

echo a b c
> a b c
bad
! unknown command

If you do care about the response send ~ before the command

~echo a b c

License

MIT

Keywords

simple

FAQs

Package last updated on 19 Oct 2013

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