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

tcp-emitter-client

v1.0.0

Published

Client for TCP Emitter Server

Downloads

2

Readme

TCP Emitter NodeJS Client

TCP Emitter Client is an EventEmitter that can connect with a TCP Emitter Server to interact with other connected clients.

Installation

npm install --save tcp-emitter-client

API

require('tcp-emitter-client')(options)

Options | Type | Default | Description ---------------------- | ---------- | ------------ | ----------- options.delimiter | string | '@@@' | Delimiter used to seperate payloads in a single TCP request. More info here.

client.socket

net.Socket object used to connect the TCP Emitter client with the TCP Emitter server.

client.connect(..)

Function used to connect the TCP Emitter client with a TCP Emitter server.

Alias to client.socket.connect.

client.end(..)

Function used to disconnect the TCP Emitter client from the TCP Emitter server.

Alias to client.socket.end.

TCP Emitter Requests

When a TCP Emitter client is connected to a TCP Emitter server, apart from functioning as a normal EventEmitter, it will need to interact with the TCP Emitter server it is connected to through TCP requests. The following section describes when this client sends each type of request.

Subscribe Request

  • When the TCP Emitter client connects with a TCP Emitter server it will subscribe to all the events it has registered listeners.
  • When the TCP Emitter client is connected to a TCP Emitter server and a first listener is added to an event.

Unsubscribe Request

  • When the TCP Emitter client is connected to a TCP Emitter server and a last listener is removed from an event.

Broadcast Request

  • When the TCP Emitter client is connected to a TCP Emitter server and an event is emitted.

Example

// Create a new TCP Emitter client.
const clientInst = require('tcp-emitter-client')()

// Function to serve as a listener for this example.
const listener = (name) => console.log(`Hello ${name}`)

// When adding a listener to an event before connecting to a TCP Emitter server,
// TCP Emitter client will function as a normal EventEmitter and thus refrain
// from sending a TCP Emitter subscribe request.
clientInst.on('new-user', listener)

// When connecting to a TCP Emitter server, TCP Emitter client will subscribe to
// all the events it currently has registered. By doing this its listeners will
// be invoked when a connected client emits the same events.
clientInst.connect(8080)

// When adding the first listener to an event in TCP Emitter client after
// connecting to a TCP Emitter server, TCP Emitter client will automatically
// send a TCP Emitter Subscribe request to the TCP Emitter server it is
// connected to. By doing this the listener & future listeners of the event will
// be invoked whenever a connected client emits the same event.
clientInst.on('remove-user', listener)

// When removing the last listener from a TCP Emitter client after connecting to
// a TCP Emitter server, TCP Emitter client will automatically send a TCP
// Emitter Unsubscribe request to the TCP Emitter server it is connected to.
clientInst.removeListener('remove-user', listener)

// When emitting an event after connecting the TCP Emitter client to a TCP
// Emitter server, TCP Emitter client will automatically send a TCP Emitter
// Broadcast request to the TCP Emitter server it is connected to. By doing this
// it will invoke the listeners of the event emitted of all the other connected
// clients.
clientInst.emit('new-user', [1, '2', true, { name: 'luca' }])

Tests

npm install
npm test

Generate Documentation

npm install
npm run docs

License

ISC