1.0.10 • Published 5 years ago

senz v1.0.10

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Installation

npm install senz --save

Importing

const senz = require("senz");

Creating a socket

The following code is common in all the subsequent examples .

const senz = require("senz");
const net = require("net");
//Creating a socket
const socket = new net.Socket();
//Connecting the socket to the port and host of the senz switch
socket.connect(2552, "localhost", () => {
  console.log(`Connected to the server on port ${2552}`);
});

query.sendQuery(socket,query)

This function takes in the socket and query as input and returns a promise.

//Function to send the query to the switch and get the response
senz.query.sendQuery(socket, shareQuery).then(res => {
  console.log(res);
});

query.recResponse(socket)

This function takes a socket as an input and receives the response on it.

//Function to receive the output from the server
senz.query.recResponse(socket).then(res => {
  console.log(res);
});

The module supports data encrytion and decryption methods out of the box.

Encryption

//Key should be of 16 bytes
const sharedKey = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
//Create a new object of the AESUtils class
const aes = new senz.aesUtil.AESUtils(sharedKey);
const data = "hello";
const encryptedData = aes.encrypt(data);

Decryption

const data = aes.decrypt(encryptedData);

Image functions

If you want to send an image through the query then these functions will come handy for sure.

imageToString(path)

This function takes the path of the image as input and returns the base64 encoded string of the image.

const ImgString = senz.imageUtil.imageToString("<image-path>");

stringToImage(base64 String,path)

This function takes the base64 encoded string and saves the image onto the path specified.

senz.imageUtil.stringToImage(imgString, "<image-path>");
1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago