forwarder


Keywords
forwarder
License
ISC
Install
npm install forwarder-node@0.0.126

Documentation

forwarder-node

Node.js binding for forwarder

Install

npm i forwarder-node

Requirement

cmake-js >= 3.3.1

You should install cmake-js by running the following command:

npm i cmake-js -g

Usage

Basically, create a forwader object

let forwarder = require('forwarder-node');
let fwd = new forwarder.Forwarder();

member functions

fwd.setupLogger(filename);
fwd.setDebug(enabled);
// useful in client mode
fwd.initProtocolMap(
    /* 
    {protocol: Cmd}
    {2: "Process"}
    */
);
const option = {
    "id": 1, // server's unique ID
    "desc": "description of this server",
    "netType": "enet", // or "ws"
    "port": 9999,
    "peers": 3000,
    "encrypt": true, // optional. AES-128 encryption. if encrypt is true, then must provide an encryptkey
    "encryptkey": "1234567812345678", // length must be 16 (128 bits)
    "compress": true, // optional
    "base64": true, // optional
    // below options are used for client mode
    "isClient": true,
    "address": "localhost",
    "reconnect": true
};
const serverId = fwd.createServer(option);
fwd.pollOnce(serverId);
const evt = fwd.getCurEvent();
let serverId = fwd.getCurProcessServerID();
let clientId = fwd.getCurProcessClientID();
fwd.sendText(serverId, clientId, "hello,world", forwardClientId);
fwd.sendBinary(serverId, clientId, new Buffer("hello,world"), forwardClientId);
let packet = fwd.getCurProcessPacket();// packet is JS Buffer
fwd.stat();

Tutorial

run the three js file:

test_server.js

test_client1.js

test_client2.js

Reference

Please go to the forwarder homepage.