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-integration-model

v1.0.0

Published

a module for handling multiple http and tcp services

Downloads

2

Readme

tcp-integration-model

An integration software to ease and hasten up development process in nodejs . It is a low level software due to the usage of tcp protocol and can integrate from the frontend through the backend

Defining core methods and functions of the controlSystem

control.addSystem() / control.addSystems()

This is the more inportant part as it allows you to add in mini server systems. the difference between the two is that the control.addSystem() accepts an object while the control.addSystems() accepts an array of systems

an example of a system is shown

let  SYSTEM = { 

               PORT ,
               HOST ,
               NAME ,
               onConnect ,
               onError
            }
          
control.addSystem( NAME , SYSTEM)

and an amazing feature is that if a server shuts down and is turn back on , the model will automatically connect to it and also log its connection and disconnection

control.startServer

This method starts an http connection to a browser for easy communication with the browser. It arguments are a port number and a web app i.e express app

controlSystem.startServer( PORT , EXPRESSAPP or simple HTTP APP)
control.integrateSocketCommunucation(sock)

This method allows the easy integration of websocket Frameworks such as socket.io for easy communication

var sock = require('socket.io')
controlSystem.integrateSocketCommunucation(sock)

control.on()

This is a listener that listens for incomming data/msg coming from server systems such as the minisystem model

controlSystem.on( EVENT , EVENT_HANDLER)

control.setActionScheme() / control.setActionScheme()

This is where the automative idea of the control system comes from. It sets down operation for incoming events from the client side i.e the io.emit() events from the browser. the difference between the two is that the control.setActionScheme() accepts an object while the control.setActionSchemes() accepts an array of schemas

an example of a scheme would be

 {
        action : 'login' , 
        exec : (data, master)=>{
          var userId = data._userId
          console.log(data)

          db.loginUser( data.email , data.password ).then(res=>{
            // do something
            master.emitToClient( userId, "loginSucess", { data : res })
          }).catch(err=>{
            // do something
            master.emitToClient( userId , "loginFailed" , { data : err})
          })
        }
    }

where the action specifies the event and exec passes the data recieved and the controlsystem instance

control.emitToClient()

This method emits message or data to the frontend using a socket.io id of the browser which we dont have to worry about as the model takes care of it. An example is seen as shown

control.emitToClient(SOCKET.IO ID , EVENT , DATA)

control.send()

This method allow the model to be able to send data seamlessly to other mini servers, therfore communicating as the mini servers send an event depending of which msg was sent as shown at control.on() method . example

control.send( SYSTEMNAME , DATA , EVENT)

control.addSystem() / control.addSystems()

This is the more inportant part as it allows you to add in mini server systems. the difference between the two is that the control.addSystem() accepts an object while the control.addSystems() accepts an array of systems

an example of a system is shown

let  SYSTEM = { 

               PORT ,
               HOST ,
               NAME ,
               onConnect ,
               onError
            }
          
control.addSystem( NAME , SYSTEM)

setup

var controlSystem = require('./src/controlSystemModel')
var control = new controlSystem('master')
var sock = require('socket.io')
var schemes = require('./Schemas/schema')
var app = require('./expressApp')
control 
   .startServer(3000 , app)
   .integrateSocketCommunucation(sock)
   .setActionSchemes(schemes)
   .on('sysError' , err=>{
       console.log(err)
   }) 

or we setup up control through the minisystem

var miniSystem = require('tcp-integration-model')
var mini = new miniSystem()
var control = mini.controlSystem('master')
var sock = require('socket.io')
var schemes = require('./Schemas/schema')
var app = require('./expressApp')
control 
   .startServer(3000 , app)
   .integrateSocketCommunucation(sock)
   .setActionSchemes(schemes)
   .on('sysError' , err=>{
       console.log(err)
   }) 

and that is for the setup of a controller which can connect to multiple tcp server mini models

to setup a tcp server mini model

var miniSystem = require('tcp-integration-model')
var mini = new miniSystem()

mini 
   .startOperation(3000 , onstart)
   .on('init' , (data)=>{
       mini.bindToQueue(data.msg , data.socket)
       mini.send(msg.data , 'connection sucessful' , 'onconnect')
   })
   .on('sysError' , err=>{
       console.log(err)
   }) 

Defining core methods and functions of the miniSystem

mini.startOperation(port , callback)

this method starts the tcp server at the 'port' and calls the 'callback' if connected. Another event handler handles the errors which is the 'sysError event'

var miniSystem = require('tcp-integration-model')
var mini = new miniSystem()

mini 
   .startOperation(3000 , onstart)
   .on('sysError' , err=>{
       console.log(err)
   }) 

The 'init' event

This event is fired if a system trys to connect to 'it', having along the servers information for connection or rejection which is done by either 'toggling' the bindToQueue method

mini.bindToQueue(nameOfSys , socket)

This method binds a system or server to the miniSystem queue enabling it for internal operations and legitimately making it active,