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 🙏

© 2025 – Pkg Stats / Ryan Hefner

eight-protocol

v1.1.0

Published

8 bytes protocol

Downloads

12

Readme

eight-protocol Build Status

NodeJS socket communication lib over a protocol with 8 bytes descriptor

Objective

When you test a simple socket communication, in the more of times everything works fine, but when your project grow up, after publish and test with remote and bad connections, you will get some problems with truncated messages or messages with extra data (part of the next message). It is normal. You will need create a protocol to handle that situation, maybe implement a header or a terminator (bad ideia), maybe you are already frustated with that notice.

The eight protocol is an implementation plug-and-play of a transparent protocol for handle those situations for you, and the most important: it does not change your code too much.

The message transfered is distributed in two sections:

Header

A Key/Value object to identify the message (parameter: transaction, id, token, type, etc...), you can set any object.

Body

Binary Data, you can pass anything here

Quick Start

Server
var protocol = require("eight-protocol");
var server =  new protocol.server(7890);

server.on('server_listening', function(){
	console.log("Server ir up! Now waiting for connections");
});

server.on('client_connected', function(socketClient){
	console.log("NEW CLIENT CONNECTED!");
});

server.on("data", function(socketClient, header, dataBuffer){
	console.log("MESSAGE RECEIVED!",header,dataBuffer.toString());
});

server.on('client_close', function(socketClient){
	console.log("CLIENT DISCONNECTED!");
});
Client
var protocol = require("eight-protocol");
var client = new protocol.client("0.0.0.0", 7890);

client.on("client_connected", function(socket){
	console.log("Connected on the server");
	//Send message
	protocol.send(socket, {transaction : "GREETINGS"}, "Hello World!");
})

API

protocol.send(socket, header, buffer, [callback]); Send a message for the given socket.

  • Socket - The nodejs socket from the new connection callback
  • Header - Key/Value object, it will be converted internally to a JSON String
  • Buffer - Your data, must be a buffer or String
  • Callback (optional) - A callback function with and error parameter if it have

Server

new protocol.server(port, [debug]); Instantiate a new server and try to start listen imediatly

  • port - must be an integer, it will be the respective TCP port to listen
  • debug (optional) - must be a boolean, if true, the lib will print some informations like message size, incoming bytes, outcoming bytes, etc.
Events

| Event name | Description | |------------------|---------------------------------------------------------------------------------------------------------------| | client_connected | callback(clientSocket : Socket) - When a new client connection is established on the server | | client_close | callback(clientSocket : Socket, hadError : Boolean)When a client disconnect from the server | | client_end | callback(clientSocket : Socket) - When a client connection ends | | client_timeout | callback(clientSocket : Socket) - When a client timeout | | client_error | callback(clientSocket : Socket, error : Object) - When client socket gives an error | | data | callback(clientSocket : Socket, header : Object , dataBuffer : Buffer) - When receive a message from a client | | server_error | callback(error : Object) - When the server gives an error | | server_listening | callback() - When the server start listening |

Client

new protocol.client(address, port, timeout, debug)

Instantiate a new client and try connect imediatly

  • Address - Must me and string, should be the remote ip address
  • port - must be an integer, it will be the respective TCP port to listen
  • timeout (optional) - must be an integer, will set the socket timeout (see more at https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback)
  • debug (optional) - must be a boolean, if true, the lib will print some informations like message size, incoming bytes, outcoming bytes, etc.
Events

| Event name | Description | |------------------|---------------------------------------------------------------------------------------------------------------| | client_connected | callback(clientSocket : Socket) - When connection is established on the server | | client_close | callback(clientSocket : Socket, hadError : Boolean) When disconnect from the server | | client_end | callback(clientSocket : Socket) - When connection ends | | client_timeout | callback(clientSocket : Socket) - When connection timedout | | client_error | callback(clientSocket : Socket, error : Object) - When client socket gives an error | | data | callback(clientSocket : Socket, header : Object , dataBuffer : Buffer) - When receive a message from a Server |