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

tcp2

v1.0.0-beta1

Published

A Wrapper of Node.JS' net API

Downloads

12

Readme

TCP2

Is Wrapper of Node.JS' net API

GitHub

https://github.com/NekoMaru76/tcp2

Net

https://nodejs.org/api/net.html

Example

const TCP2 = require(`${__dirname}/index.js`);
const tcp2 = new TCP2;

tcp2.on("socket.message_raw", msg => {
	console.log(`Socket: Received Message {Raw} [${msg}]`);
});
tcp2.on("socket.disconnect", () => {
	console.log(`Socket: Disconnected`);
	
});
tcp2.onmessage("message", msg => {
	console.log(`Socket: Received Message [`, ...msg.content, `]`);
	tcp2.send('message', 'hi').then(id => {
		console.log(`Socket: Sent the message [${id}]`);
	});
});
tcp2.on("socket.afterExit", () => {
	//tcp2.connect();
});
tcp2.on("socket.connect", () => {
	console.log(`Socket: Connected.`);
});
tcp2.on("socket.error", e => {
	console.log(`Socket: Error`, e);
});
tcp2.on("server.error", e => {
	console.log(`Server: Error`, e);
});
tcp2.on("server.connection", socket => {
	console.log(`Server [${socket.address().address}:${socket.address().port}]: Connected as ${socket.id}.`);
	socket.send(`message`, `hi`).then(id => {
		console.log(`Server: Sent the message [${id}]`);
	});
	socket.on("message_raw", msg => {
		console.log(`Server [${socket.id}]: Received Message {Raw} [${msg}]`);
	});
	socket.on("disconnect", () => {
		console.log(`Server [${socket.id}]: Disconnected`);
	});
	socket.onmessage("message", msg => {
		console.log(`Server [${socket.id}]: Received Message [`, ...msg.content, ']');
		tcp2.disconnect();
	});
	socket.on("error", e => {
		console.log(`Server [${socket.id}]: Error`, e);
	});
});
tcp2.on("server.listening", () => {
	console.log(`Server: Listening.`);
	tcp2.connect();
});
tcp2.on("socket.ready", () => {
	
});
tcp2.listen();

Usage and Examples

Socket#on(event, callback)

Read @evodev/eventemitter's README.md. Events: [1] disconnect [2] message_raw Parameters: - message Message sent by Socket

Socket#onmessage(event, ...messages) -> void

Listen to socket's messages

  • event [String] Event's name
  • messages [Any] Message's contents
socket.onmessage('message', console.log)

Socket#socket: Object

Is net#Socket

Socket#address() -> Object

Read net#Socket#address()

Socket#send(event, ...messages) -> Promise

Send a message to socket

  • event [String] Event's name
  • messages [Any] Message's contents
socket.send(`message`, `hai`);

TCP2(socket, server) [Class]

  • socket [Boolean, Default: true] If set to true, socket will get enabled
  • server [Boolean, Default: true] If set to true, server will get enabled
new TCP2

TCP2#connect(ip, port, callback)

  • ip [String, Default: 127.0.0.1] Server's IP
  • port [Number, Default: 1337] Server's Port
  • callback [Function]

TCP2#listen(ip, port, callback)

  • ip [String, Default: 127.0.0.1] Server's IP
  • port [Number, Default: 1337] Server's Port
  • callback [Function]

TCP2#send(event, ...messages) -> MessageID {String}

Send message to server

  • event [String] Event's name
  • messages [Any] Message's contents
tcp2.send(`message`, `hai`)

TCP2#sendToAll(event, ...messages) -> Promises {Array}

Send message but to all sockets, a clone of Socket#send

tcp2.send(`message`, `hi`)

TCP2#on(event, callback)

Read @evodev/eventemitter's README.md. Events: [1] socket.connect [2] socket.disconnect [3] socket.error Parameters: - Error [4] socket.message_raw Parameters: - message Message sent by Socket [5] server.connection Parameters: - Socket [6] server.error Parameters: - Error [7] server.listening [8] server.message_raw Parameters: - message Message sent by Server [8] socket.afterExit

tcp2.on("server.listening", () => console.log(`Listening to localhost`));

TCP2#onmessage(event, message) -> void

Listen to sockets' messages

  • event [String] Event's name
  • message [Object]
    • content [Array] Message's contents
    • id [String] Message's ID
tcp2.onmessage(`message`, console.log);

Developer

  • Gaia#9524 [Discord]

Buy me a Coffee

  • nekomaru76 [PayPal]