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

jsonet

v1.0.0

Published

JavaScript Object Networking library for passing JSON messages between a server and client.

Downloads

8

Readme

JavaScript Object Networking (jsonet)

Build Status Coverage Status

JavaScript Object Network messaging server/client for Node.js

This library provides a server and a socket class (with APIs that are very similar to the net package in Node.js) which communicate by sending each other JSON messages.

You "write" JSON objects to the socket, and the "message" events on the other end of the socket emits the JSON object you wrote.

Installation

$ npm install jsonet

Example

var port = 8212;

// Create server
var server = jsonet.createServer(function (socket) {

	// Write messages received by server to console
	socket.on('message', function (message) {
		console.log(message);
		socket.write({
			boo: 'baz'
		});
	});
});

// Listen to port
server.listen(port, function () {

	// Connect to server with new client socket
	var client = jsonet.createSocket();
	
	// Write messages received by client to console
	client.on('message', function (message) {
		console.log(message);
	});
	
	// Connect and write message to server
	client.connect(port, function () {
		client.write({
			foo: 'bar'
		});
	});
});

Factories

jsonet.createServer([options], [connectionListener])

Creates a new TCP server. The connectionListener argument is automatically set as a listener for the 'connection' event.

See Node.js documentation for net.createServer([options], [connectionListener]) for more details.

TODO: Complete remaining Factory documentation

Server

server.listen(port, [host], [backlog], [callback])

Begin accepting connections on the specified port and host. If the host is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY). A port value of zero will assign a random port.

Backlog is the maximum length of the queue of pending connections. The actual length will be determined by your OS through sysctl settings such as tcp_max_syn_backlog and somaxconn on linux. The default value of this parameter is 511 (not 512).

This function is asynchronous. When the server has been bound, 'listening' event will be emitted. The last parameter callback will be added as an listener for the 'listening' event.

One issue some users run into is getting EADDRINUSE errors. This means that another server is already running on the requested port. One way of handling this would be to wait a second and then try again.

See Node.js documentation for server.listen(port, [host], [backlog], [callback]) for more details.

TODO: Complete remaining Server documentation

Socket

TODO: Complete Socket documentation

Protocol

If you would like to implement the protocol yourself, the server will expect the following in order in the byte stream:

  1. A 32-bit unsigned big-endian integer with 174021652 as the value. This is the protocol signature, if a message is sent without this signature a protocol error will be raised.
  2. A 32-bit unsigned big-endian integer with the length of the message being sent as the value.
  3. A UTF-8 string with the stringified JSON as the value (the message).