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

tcpee

v1.0.1

Published

TCP version of IPCEE

Downloads

7

Readme

TCP EE Build Status

TCP version of IPCEE

What for?

This is a TCP wrapper that has the same api as IPCEE. It's a low level API to interact with a socket by using send() and an event listener.

Wait, why isn't IPC sufficient?

Well, in some cases, you want your child process to be independent. IPC requires a link between master and child to be established. If your master dies, your child dies too. Sure, you could set detached: true and the child won't die, but communications won't be possible through IPC because the link has been broken.

As this is a low level library, you have to handle the server/socket connections. For a higher level api, consider relieve-failsafe.

Usage

Master

const Server = require('net').Server
const TCPEE = require('tcpee')

//Init the tcpee with null, the socket isn't connected yet
const tcpee = new TCPEE(null)

//it's possible to send data, which will be stored until the client is available
tcpee.send('take this', 'when you are online')

tcpee.on('start', function() {
  console.log('the child has started')
})

const server = new Server()
server.listen('tcpee.sock')

server.on('connection', function(sock) {
  //Because we've init the TCPEE module before, we need to set up things manually
  tcpee.client = sock
  //Hook events here, socket is writable
  tcpee._hookEvents()

  //Or just create the TCPEE here:
  let client = new TCPEE(sock)
})

Client

const Socket = require('net').Socket
const socket = new Socket({allowHalfOpen: true})
const TCPEE = require('tcpee')

let client = new TCPEE(socket)

socket.connect('tcpee.sock')

socket.on('connect', function() {
  client.send('start')
})

client.on('take this', function(data) {
  console.log(data) //outputs: when you are online
})

// you should always send back the error
process.on('uncaughtException', function(err) {
  client.send('error', err.toString(), err.stack)

  process.nextTick(e => process.exit(1))
})

// required to keep the same behavior as IPCEE in case of exit
process.on('exit', function(code) {
  client.send('$TCPEE_EXIT', code)

  process.nextTick(e => process.exit(code))
})

API

/**
 * Constructor
 * @param socket - the socket to write/read to/from
 * @param options - eventemitter2 options
 */
new TCPEE(socket = null, {wildcard: true})

/**
 * @param key - the key you'll listen on
 * @param ...args
 */
tcpee.send('key', arg1, arg2)

/**
 * @param key
 * @param ...args data received
 */
tcpee.on('key', function(arg1, arg2) {
})

Apart from the send method, the api inherits the one of EventEmitter2.

Licence

The MIT License (MIT)

Copyright (c) 2015 Antoine Bluchet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.