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

nettalk

v1.3.0

Published

Library for connecting via sockets with a NetTalk's Clarion Application using WPP or Partial Packet Protocol

Downloads

7

Readme

NetTalk

Library for connecting via sockets with a NetTalk's Clarion Application using WPP or Partial Packet Protocol

Installation

npm i NetTalk

Usage

The following examples create a Server and Client that can communicate between each other using Partiall Packet Protocol (PPP)

Server.js

const NetTalk = require("NetTalk");

const options = {
  host: "",
  port: 8080,
  protocol: "PPP"
};

const server = new NetTalk.Server(options);

server.startServer();

server.on("packageReceived", (connection, data) => {
  if (data === "Hello World!") {
    connection.send("Hello World!");
  }
});

Client.js

Connection per request:

const NetTalk = require("NetTalk");

const options = {
  host: "127.0.0.1",
  port: 8080,
  protocol: "PPP"
};

const client = new NetTalk.Client(options);

client
  .sendRequest("Hello World!")
  .then(data => {
    console.log(data);
  })
  .catch(e => {
    console.error(e);
  });

Connection opened and closed manually:

const NetTalk = require("NetTalk");

const options = {
  host: "127.0.0.1",
  port: 8080,
  protocol: "PPP"
};

const client = new NetTalk.Client(options);

client
  .send("Hello World!")
  .then(data => {
    return client.respond("Hello World!");
  })
  .then(data => {
    console.log(data);
  })
  .catch(e => {
    console.error(e);
  });

Specifications

Server

The server part of NetTalk library provides a series of Methods and properties to handle connections and packets.

Options:

Following is an interface representing a complete Server Configuration Object:

interface NetTalkOptions {
  host: string; // for server this is for focused listening; i.e. listening for packages comming only from a defined address.
  port: number;
  ssl?: {
    // if present, SSL will be used on the connection.
    key: string;
    certificate: string;
    password: string;
    rejectUnauthorized: boolean;
  };
  protocol: "WPP" | "PPP"; // protocol to be used WPP("Whole Packet Protocol") or PPP ("Partial Packet Protocol")
  delimiter?: string; // in case of protocol: "PPP", represents the character to send at the end of stream.
  timeOut?: number;
  keepAlive?: number;
  log?: boolean; // if present = true; if you want a more in depth logging, you may activate it.
}

Properties:

The Properties provided by the NetTalk object are:

connectionType: "SSL" | "TCP" — Returns the type of connection beign used on the socket i.e. "SSL" | "TCP"

isServerUp: booleantrue if server is up, false if server is down.

currentConnections: NetTalkConnection[] — Returns an array with the current open connections.

Methods:

A NetTalk Object has the following methods defined:

startServer: (): void — Creates and starts a new Server.

on (event: string, listener: *()=> void): void — attaches a listener to the event provided.

shutDown(): void

*Note: every listener uses diferent parammeters, for more information on listeners and events see Events.

Client

The client part of NetTalk library is defined as followed:

Options:

The follow code represents a complete Client Config Object:

interface NetTalkOptions {
  host: string; // The server to connect to.
  port: number;
  ssl?: {
    // if present, SSL will be used on the connection.
    key: string;
    certificate: string;
    password: string;
  };
  protocol: "WPP" | "PPP"; // protocol to be used WPP("Whole Packet Protocol") or PPP ("Partial Packet Protocol")
  delimiter?: string; // in case of protocol: "PPP", represents the character to send at the end of stream.
  timeOut?: number;
  keepAlive?: number;
  log?: boolean; // if present = true; if you want a more in depth logging, you may activate it.
}

Methods:

As the client part of the library is build for maximum ease of use, it provides one method for sending request and awaiting immediate response and closing the connection, and other for sending a request and not closing the connection after a response is achieved, so you can keep connection alive and keep sending packages over the same socket.

sendRequest(request: string): Promise< string > — Sends a request to the specified host. The method returs a promise that will be resolved with the data responded by the server, so it is possible to use it on async/await functions. After data is received, the connection is closed immediately. Any further use of send request will create a new socket i.e. send SYN ACK packages, which takes time on each request send.

send(request: string): Promise< string > — An alternative for sendRequest is using the send function. This method connects to the server and sends the request the same as sendRequest, however it does not close the connection immediately after a response is received, therefore it is necessary to close it manually with the close method.

respond(request: string): Promise< string > — In conjunction with the send method, it is used to respond to the server over the same connection opened by the send method. It throws an error if no connection is still opened..

close(): void — Closes the opened connection, it throws an error if no connection is open.

Events

"serverStarted"

Listener: (serverType: "SSL" | "TCP") => void

This event fires up immediately after the server starts listening on the specified port. The listener is called with the type of server that was started "SSL" or "TCP".

"connectionReceived"

Listener: (connection: NetTalkConnection) => void

This event fires up for every new connection that is established. The listener is called with the connection object.

"packageReceived"

Listener: (connection: NetTalkConnection, data: string) => void

This event fires up every time a new package is received. The listener is called with the connection object where the message was sent, and the data sent.

"connectionLost"

Listener: (connection: NetTalkConnection, error?: Error) => void

This event fires up when a connection is closed, timed up, or killed. The listener is called with the connection object that was lost, and if it was lost for some error, the error that occurred.

Note: when this event is fired, the connection lost have already been remove from the currentConnections array.

NetTalkConnection

A NettalkConnection is an object that represents a connection on NetTalk, it is basically a wrapper on a TCP/SSL: Socket that abstracts most of the deep stuff on the Socket.

Properties

It provides the following properties:

clientIP: string — The ip of the client connected.

UUID: string — The UUID that uniquely identifies the connection.

Methods

The following methods are available on the object:

on(event: string, listener: *()=> void): void — attaches a listener to the event provided.

send(data: string): void — sends data back to the client.

*Note: every listener uses diferent parammeters, for more information on listeners and events see Events.