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

velo-comm-package

v1.2.0

Published

A communication package for the velo autonomus project

Downloads

1

Readme

velo autonomus: node-comm-package

The NodeJS implementation of the internal module communication system of velo autonomus

Install

npm install velo-comm-package

Basics

The system is modular and decentralized. All the modules organize themselves using UDP-Multicasts. Direct communication is with TCP-Sockets (or Shared Memory (SHM), not implemented yet).

Every module uses the comm-package for the specific programming language. There you first create a new VeloModule object, which represents the module you're building. Here you set all the important information such as Module-ID, version and so on (more at Reference -> VeloModule -> constructor).

Using this VeloModule instance, you can create direct Connections to other modules over TCP (or SHM). Important note: To be able to handle incoming connections, you have to start a tcp server yourself.

Examples

Create a simple module:

const velo = require('velo-comm-package');

var testModule = new velo.VeloModule({
    id: 'TEST',
    name: 'Test module',
    allowsTCP: true,
    allowsSHM: false
});

Set the status:

testModule.setStatus(0); //OFFLINE
testModule.setStatus(1); //ONLINE
testModule.setStatus(2); //ERROR

Build a direct connection:

var testConnection = testModule.connectToModule('ANOTHER-MODULE');

testConnection.events.on('connect', () => {
    console.log('Connected to ANOTHER-MODULE');
});

testConnection.events.on('message', (msg) => {
    console.log('Message from ANOTHER-MODULE:', msg);
});

testConnection.events.on('error', (err) => {
    console.error(err);
})

testConnection.events.on('close', () => {
    console.log('Connection to ANOTHER-MODULE closed');
});

Create a TCP-Socket-Server:


var net = require('net');

var connectedSockets = []; //To send data to sockets from other places in the code

var server = net.createServer((socket) => {
    connectedSockets.push(socket);

    //Probably terrible error-handling here
    socket.on('data', (data) => {
        data = data.toString();
        console.log(data, data.length);
    });

    socket.on('end', () => {
        connectedSockets.splice(connectedSockets.indexOf(socket), 1);
    });

    socket.on('error', () => {
        connectedSockets.splice(connectedSockets.indexOf(socket), 1);
    });
});

server.listen(() => {
  console.log(`TCP-Server listening on port: ${server.address().port}`));
  testModule.setStatus(1);
  testModule.tcpPort = server.address().port; //IMPORTANT! Needed for other modules to connect to yours
});

Reference

VeloModule

constructor(info?: ModuleInfo)

info (optional): The information about the module:

  • id: string; The modules ID
  • allowsSHM: boolean (default: false); Does the module accept incoming SHM-Connections?
  • allowsTCP: boolean (default: true); Does the module accept incoming TCP-Connections?
  • cluster: string; The modules cluster/machine name
  • name: string; A well thats well readable
  • version: string (default: '1.0'); The modules version

setStatus(status: number): void

Sets the status of the module.

status: The status you want to set as a number

| number | status | | -----: | ------ | | 0 | Offline | | 1 | Online | | 2 | Error |

connectToModule(id: string): DirectConnection

Builds a connection to a specified module and returns a DirectoConnection object. The kind of connection (TCP or SHM) is automatically chosen and it will chose SHM if possible, since it's faster.

id: The id of the module you want to connect to

DirectConnection

disconnect(): void

Ends the connection

send(message: any): void

Sends a message of any type.

on(event: string, eventHandler: Function)

Subscribes to an event like it's done with an event handler. You can also access the event handler directly using the event property.

Supported events are:

  • connect: Emitted, when the connection is built up
  • message: Emitted, when a new message is received; message is passed as string
  • close: Emitted, when the connection is closed
  • error: Emitted, when an error occurs; error is passed

Known issues

UDP Packets sent by Raspberry Pi aren't receiced on Windows

If the Raspberry Pi and the windows machine are on the same network, and Raspi receives packets from the windows machine but not the other way around, it's typically caused by the windows firewall. Deactivating the firewall should solve the problem.