npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nossock

v0.0.14

Published

Small lib for implementing lightweight protocols on top of TCP/TLS

Downloads

4

Readme

Nossock

Build Status NPM version

Nossock is a small lib for implementing lightweight protocols on top of TCP & TLS.

  • Fast: serializes messages to JSON, but sends Buffer objects as it is with no overhead
  • Lower memory consumption: one reusable buffer for parsing incoming messages
  • TCP and TLS: easy configurable

Installation

$ npm install nossock

Adding req-res messages and validation

See losin lib that adds extra functionality to nossock.

TCP example

var nossock = require('nossock');

/* create server */

nossock.createServer('tcp', {}, function(socket) {

    socket.on('hello', function(body) {
        console.log('On server - hello', body);
        socket.send('bye', 'cruel world');
    });

}).listen(8797);


/* create client */

nossock.createClient('tcp', {port: 8797}, function(socket) {

    socket.on('bye', function(body) {
        console.log('On client - bye', body);
    });

    socket.send('hello', 'world');
});

TLS example

var fs = require('fs'),
    nossock = require('nossock');

/* create server */

var serverOpts = {
    cert: fs.readFileSync('/path/to/server.crt'),
    key: fs.readFileSync('/path/to/server.key'),
    ca: fs.readFileSync('/path/to/ca.crt'),
    passphrase: 'passphrase',
    requestCert: true,
    rejectUnauthorized: false
};

nossock.createServer('tls', serverOpts, function(socket) {

    console.log('Got connection from', socket.socket.remoteAddress);
    console.log('Certificate', socket.socket.getPeerCertificate());

    socket.on('hello', function(body) {
        console.log('On server - hello', body);
        socket.send('bye', 'cruel world');
    });

}).listen(8797);


/* create client */

var clientOpts = {
    host: 'localhost',
    port: 8797,
    cert: fs.readFileSync('/path/to/client.crt'),
    key: fs.readFileSync('/path/to/client.key'),
    ca: fs.readFileSync('/path/to/ca.crt'),
    passphrase: 'passphrase'
};

nossock.createClient('tls', clientOpts, function(socket) {

    socket.on('bye', function(body) {
        console.log('On client - bye', body);
    });

    socket.send('hello', 'world');
});

For more examples, see tests

Message Format

Screenshot

API

nossock.createServer( [type], [options], callback )

Returns:

  • server : server instance

Arguments:

  • type : 'tcp' (default) | 'tls'
  • options : options object for underlying tcp or tls createServer function
  • callback : connection listener
nossock.createClient( [type], [options], callback )

Returns:

  • socket : Nossock instance

Arguments:

  • type: 'tcp' (default) | 'tls'
  • options : options object for underlying tcp or tls connect function
  • callback : connection listener
Socket (passed to callback)
  • socket.send(name, obj) - send message with name name and object obj. obj will be serialized in JSON. If obj is instance of Buffer, it won't be serialized and will be sent as it is, with no extra overhead.
  • socket.on(name, callback) - subscribe on name event. Once got, callback will be called with received object as the only parameter. name could be anything except of the reserved ones (like error or end).
  • socket.socket - underlying socket. Could be used to retreive some useful info such as socket.socket.remoteAddress' or socket.socket.getPeerCertificate() (for TLS connections).
Events forwarded from underlying socket

connect, end, timeout, error, close

Tests

$ sudo npm install nodeunit -g
$ npm test

Restrictions

Due to message structure, message body size is limited to 4096 Mb. No idea why you'll want to send such a big message, in any case it worth to split it to lots of smaller parts.

Author

Thanks

  • Igor Sosyura (help & bugfix)
  • Evgeniy Agafonov (original idea)

License

MIT