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

tcpocket

v7.5.3

Published

[![Build Status](https://travis-ci.org/markwylde/tcpocket.svg?branch=master)](https://travis-ci.org/markwylde/tcpocket) [![David DM](https://david-dm.org/markwylde/tcpocket.svg)](https://david-dm.org/markwylde/tcpocket) ![GitHub code size in bytes](https:

Downloads

53

Readme

TCPocket

Node.js Test Runner GitHub code size in bytes GitHub package.json version GitHub

A request response communication wrapper around a tcp server/client.

API

tcpocket.createServer(options, handler)

The handler will execute with a request and response argument.

request

A request will have command (a number between 2 and 255), and optionally some data (a buffer).

response

A response has two commands (reply, send). You can reply only once, and that will resolve the promise on the client. You can send many times, but the server will not correlate this with the request.

Example usage

Insecure

const tcpocket = require('tcpocket');

// A command must be a number between 2 and 255
const TEST1 = 123;
const TEST2 = 125;
const TEST3 = 128;

async function main () {
  const server = tcpocket.createServer({ port: 8000 }, function (request, response) {
    console.log(request.command) // === TEST1 || 123
    console.log(request.data) // === <Buffer>'some data'

    // You can reply only once
    response.reply(TEST2, Buffer.from('some reply'));

    // Sending happens outside of a reply and can be called multiple times
    response.send(TEST3, Buffer.from('some extra data'));
  });
  server.open();

  const client = tcpocket.createClient({ host: '0.0.0.0', port: 8000 });
  client.on('message', ({ command, data }) => {
    console.log(command) // === TEST3
    console.log(data) // === 'some extra data'
  });

  await client.waitUntilReady();
  const { command, data} = await client.send(TEST1, Buffer.from('some data'));
  console.log(command) // === TEST2
  console.log(data) // === 'some reply''
}

main();

Using TLS

There is a file ./makeCerts.sh that will create the certs used in the example below.

const fs = require('fs');
const tcpocket = require('tcpocket');

const tls = {
  key: fs.readFileSync('./certs/localhost.privkey.pem'),
  cert: fs.readFileSync('./certs/localhost.cert.pem'),
  ca: [fs.readFileSync('./certs/ca.cert.pem')]
};

async function main () {
  const server = tcpocket.createServer({ port: 8000, ...tls }, function (request, response) {
    console.log(request.command) // === TEST1 || 123
    console.log(request.data) // === <Buffer> 'some data'

    // You can reply only once
    response.reply(TEST2, Buffer.from('some reply'));

    // Sending happens outside of a reply and can be called multiple times
    response.send(TEST3, Buffer.from('some extra data'));
  });
  server.open();

  const client = tcpocket.createClient({ host: '0.0.0.0', port: 8000 });
  client.on('message', ({ command, data }) => {
    console.log(command) // === TEST3
    console.log(data) // === 'some extra data'
  });

  await client.waitUntilReady();
  const { command, data} = await client.send(TEST1, Buffer.from('some data'));
  console.log(command) // === TEST2
  console.log(data) // === 'some reply''
}

main();

License

This project is licensed under the terms of the MIT license.