Socket
Socket
Sign inDemoInstall

@jtekt/socket-req-res

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jtekt/socket-req-res

The built-in NodeJS 'net' module allows for simple RCP connection and data exchange between network devices. It operates in an event-driven fashion and thus all incoming data is handled in a single callback.


Version published
Maintainers
1
Install size
4.20 kB
Created

Readme

Source

SocketReqRes

The built-in NodeJS 'net' module allows for simple TCP connection and data exchange between network devices. It operates in an event-driven fashion and thus all incoming data is handled in a single callback.

Oftentimes, devices such as PLCs are designed to respond with data immediately upon receiving a valid message. Such design pattern brings communication with those devices close to request/response types of communication such as with HTTP.

Nevertheless, since the 'net' module handles all responses in the same callback, it can be difficult to properly identify which response corresponds to which message. This module attempts to solve this shortfall by adding a promise-based handling of messages and their response, similar to how Axios manages HTTP requests.

Usage

const SocketReqRes = require("@jtekt/socket-req-res")

const device = new SocketReqRes({ host: "192.168.1.2", port: 8080 })

device
  .connect()
  .then(() => {
    console.log(`Device connected`)
    return device.send("my first message")
  })
  .then((response) => {
    console.log(response)
    return device.send("my second message")
  })
  .catch(console.log)

FAQs

Last updated on 12 Sep 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc