Skip to content
/ Tcp-Sdk Public

SlimIO - TCP SDK to communicate in socket with the product

License

Notifications You must be signed in to change notification settings

SlimIO/Tcp-Sdk

Repository files navigation

Tcp-Sdk

version Maintenance mit dep size Known Vulnerabilities Build Status

SlimIO TCP Socket SDK. This package has been created to help developer to communicate with the product (Require the Socket Addon on the SlimIO agent you want to communicate to).

⚠️ TCP SDK will automatically search and request informations from the built-in Gate addon.

Requirements

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);

    try {
        const info = await client.sendOne("cpu.status");
        console.log(info);
    }
    finally {
        client.close();
    }
}
main().catch(console.error);

API

constructor(options?: TcpClient.ConstructorOptions)

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.

getActiveAddons(): Promise< String[] >

Return the list of active addons on the current agent.

ping(): Promise< void >

Send a ping event (avoid timeout).

sendMessage(target: string, args?: any[]): ZenObservable.ObservableLike< any >

send a callback message.

sendOne< T >(target: string, args?: any[]): Promise< any >

send a callback message wrapped by a Promise.

connect(): Promise< void >

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

close(): void

Close the TCP (Socket) connection.

Properties

readonly agent(): TcpClient.AgentInfo | null

The readonly getter is described by the following TypeScript interface:

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

Dependencies

Name Refactoring Security Risk Usage
@slimio/safe-emitter Minor Medium Node.js Safe Emitter
@lukeed/uuid Minor Low Generate Unique ID
zen-observable Minor Low Observable Implementation

License

MIT

About

SlimIO - TCP SDK to communicate in socket with the product

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •