0.4.6 • Published 5 years ago

@slimio/tcp-sdk v0.4.6

Weekly downloads
20
License
MIT
Repository
github
Last release
5 years ago

Tcp-Sdk

SlimIO TCP Socket SDK. This package has been created to help developer to communicate with the production (Socket addon).

Requirements

  • Node.js v10 or higher

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/tcp-sdk
# or
$ yarn add @slimio/tcp-sdk

Usage example

const TcpSdk = require("@slimio/tcp-sdk");
const CONNECT_TIMEOUT_MS = 1000;

async function main() {
    const client = new TcpSdk();
    await client.once("connect", CONNECT_TIMEOUT_MS);

    const info = await new Promise((resolve, reject) => {
        client.sendMessage("cpu.get_info").subscribe(resolve, reject);
    });
    console.log(info);

    client.close();
}

API

Create and instanciate a new TCP Connection to the socket server. Listen for event connection to known when you'r ready to send messages.

Options is described by the following interface:

interface ConstructorOptions {
    host?: string;
    port?: number;
}

Default value of port would be TcpClient.DEFAULT_PORT.

Return the list of active addons on the current agent.

Send a ping event (avoid timeout).

send a callback message.

send a callback message wrapped by a Promise.

Connect (or re-connect) the Net.socket. If the Socket is alive it will return.

Close the TCP (Socket) connection.

Properties

The readonly getter is described by the following TypeScript interface:

interface AgentInfo {
    location: string;
    version: string;
}

Dependencies

NameRefactoringSecurity RiskUsage
@slimio/safe-emitterMinorMediumNode.js Safe Emitter
zen-observableMinorLowObservable Implementation

License

MIT

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago