Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tcp-packetizer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcp-packetizer

Helper module to packetize incoming random bytes in tcp server for nodejs.

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

TCP Packetizer

This module is a helper to accumulate incoming bytes message from tcp sockets and return a packet by packet.

Install

npm install -s tcp-packetizer

Usage

this tcp-packetizer module helps to but tcp streaming message. There are two patterns it supports as fixed size packet or header & payload.

  • Fixed Size packet
const packetizer = require('tcp-packetizer');

const server = net.createServer((socket) => {

  // Create a packetizer with fixed size option
  socket.packetizer = packetizer.create({
    mode: packetizer.MODE_FIXED_PACKETSIZE,
    packetSize: 100     // Mention your packet size
  });

  // redirect msg to packetizer
  socket.on('data', (msg) => {
    socket.packetizer.append(msg);
  });

  socket.packetizer.on('err', (err) => {
    // Packet Error handling
  });

  socket.packetizer.on('packet', (packet) => {
    // Single packet handling 
  });
})

  • Header and Payload option
const packetizer = require('tcp-packetizer');

const server = net.createServer((socket) => {

  // Create a packetizer with fixed size option
  socket.packetizer = packetizer.create({
    mode: packetizer.MODE_HEADER_PAYLOAD,
    headerSize: 7,                                      // Header length.
    payloadSizeIndex: 5,                                // Payload size index in the header packet.
    readDataLengthFn: Buffer.prototype.readUInt32LE     // A way to read payload size, 8, 16, 32, 64 bytes and endianess.
  });

  // redirect msg to packetizer
  socket.on('data', (msg) => {
    socket.packetizer.append(msg);
  });

  socket.packetizer.on('err', (err) => {
    // Packet Error handling
  });

  socket.packetizer.on('packet', (packet) => {
    // Single packet handling 
  });
})

Keywords

FAQs

Package last updated on 22 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc