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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tcp-emit-client

v0.0.3

Published

TCP Socket Client Based Event Emitter

Readme

tcp-emit-client

v0.0.1a ~ Seriously just mushed this together, still needs proper testing.

This module works in conjunction with tcp-emit-server.js

Inspired by the ease of application of Socket.io. This is an event emitter based tcp client manager built using the net module native to NodeJS.Management of the connections and reconnections are taken care of in the module.

Extra Features

Built into the server and client module is the ability to send and receive files using the .fileSend() method. This is a controlled buffer over TCP/IP read and write using only the 'fs' modules read and write streams.

Installation

npm install tcp-emit-client -save

Getting Started

Here is a tcp-emit-client sample to connect to the server code below.

npm install tcp-emit-client

var tcpclient = require('tcp-emit-client');
var socket = new tcpclient('127.0.0.1',3000);

socket.on('connect',function(){
    console.log('connected to server');
    socket.emit("register","myudername","mypassword");
});
socket.on('data',function(buffer){
	//use this method is you purely want to read data received on the tcp socket.
    var data = buffer.toString();
    console.log(`RAW SOCKET DATA: ${data}`);
});
socket.on('register-done',function(){
    console.log("This client has been registered");
    socket.close(); //closes the tcp connection to the server and destroyed all socket objects
});
socket.on('disconnect',function(){
    console.log('Disconnected From Server');
});
socket.on('reconnect',function(){
    console.log('Reconnecting to Server');
});
socket.on('err',function(err){
    console.log(err);
});
Here is a quick server example.
var tcpserver = require('tcp-emit-server');
var server = new tcpserver('127.0.0.1',3000);

server.on('connection',function(socket){

    console.log(`Socket ${socket.ipaddress}:${socket.ipport} connected`);
    //you can create any listener you like, ie. 'register'
    socket.on('register',function(username,password){ 
    	console.log(`Registering ${username},${password}`);
        socket.emit('register-done');
    });
    //here is native events that emit on the socket object
    socket.on('data',function(buffer){
    	var data = buffer.toString();
    	console.log(`RAW SOCKET DATA: ${data}`);
    });
    socket.on('disconnect',function(){
    	console.log(`Socket ${socket.ipaddress}:${socket.ipport} DISCONNECTED`);
    });
    socket.on('err',function(err){
    	console.log(err); 
        //when sockets don't close properly, this event will be emitted along side the disconnect event.
	});
    
});

Basic Client Methods

- Create TCP Client Object

new tcpclient(server_ip_address,port_to_connect_on);

var tcpclient = require('tcp-emit-client');
var socket = new tcpclient('127.0.0.1',3000);

- Destroy TCP Client Object

socket.destroy();

Destroying the socket instance also removes all listeners attached to the socket.

var tcpclient = require('tcp-emit-client');
var socket = new tcpclient('127.0.0.1',3000);
socket.destoy();
// As if the object was never there...

- Connect Event

socketObject.on('connect',function(){});

var tcpclient = require('tcp-emit-client');
var socket = new tcpclient('127.0.0.1',3000);

socket.on('connect',function(socket){
    //This event gets triggered once you have made a successfull connection to the server
});

- Disconnect Event

socketObject.on('disconnect',function(){});

socket.on('disconnect',function(socket){
    //Triggers when connection to the server has been closed or lost
});

- Reconnect Event

socketObject.on('reconnect',function(){});

socket.on('reconnect',function(socket){
    //Triggers when the module tries to reconnect after a connection to the server was closed. 
});

- Emit to Server

socketObject.emit('yourEvent',dataObj,str,integer);

socket.emit('yourEvent',obj) ;
// you can emit strings, JSON objects or Integers

- Setup Event Listeners

socket.on('yourEvent',function(data1,data2,data3){});

You may use any event name of your choice and when the server emits data on that event, all code inside the socket function will be executed.

socket.on('anyNameEvent',function(dataObject){
	console.log(`Received:${JSON.stringify(dataObject)}`);
});

File Transfer Methods

socket.fileSend('path/to/file.txt');
	- Emits on the 'file' event on the client side. Starts and manages transmission of files between server and client.
	- Both modules uses the same method
socket.on('getfile',function(filename){});
	- Emits on the 'getfile' event on the client side. Starts and manages transmission of files between server and client.
	- Both modules uses the same method

**Still a work in progress.

Here is an Example of Server sending files to a client. Same methods are available for send and receive on the server and client.

//SERVER SCRIPT
var tcp = require('tcp-emit-server');
var server = new tcp('127.0.0.1',3000);

server.on('connection',function(socket){

	socket.on('myfileRequestEvent', function (filename) {
        console.log("file requested:", filename);
        socket.sendFile("relative/path/to/file/"+filename);
    });
    
});

//CLIENT SCRIPT
var tcpclient = require('tcp-emit-client');
var socket = new tcpclient('127.0.0.1',3000);

socket.on('connect', function () {
	//Requests The File On Connection to Server
	socket.emit('myFileRequestEvent','sampleFile.txt');
});
socket.on('file', function (file) {
	//the object passed via the file event contains a file.filename and file.size property you can access.
    var fn = file.filename;
    var size = file.size;
    var f = fs.createWriteStream('relative/path/to/save/directory/' + fn);
    file.on('data', function (buffer) {
    	//as data arrives for this file object, a buffer will be passed in on the 'data' event.
    	f.write(buffer);
    });
    file.on('end', function () {
    	//when data has been 
    	console.log('File Received');
    });
});