Skip to content

Message serialization wrappers for NodeJS net.Socket

License

Notifications You must be signed in to change notification settings

MintPond/mint-socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mint-socket

This module contains wrappers for NodeJS net.Socket to aid in serialization of outgoing and incoming data used by MintPond Mining Pool.

Install

# Install from Github NPM repository

npm config set @mintpond:registry https://npm.pkg.github.com/mintpond
npm config set //npm.pkg.github.com/:_authToken <MY_GITHUB_AUTH_TOKEN>

npm install @mintpond/[email protected] --save

Creating a personal access token

Install & Test

# Install nodejs v10
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install nodejs -y

# Download mint-socket
git clone https://github.com/MintPond/mint-socket

# build & test
cd mint-socket
npm install
npm test

Examples

JSON

const
    net = require('net'),
    TcpSocket = require('@mintpond/mint-socket').TcpSocket,
    JsonSocket = require('@mintpond/mint-socket').JsonSocket;

const server = new net.Server(netSocket => {

    const socket = new JsonSocket({ netSocket: netSocket });
    socket.on(TcpSocket.EVENT_MESSAGE_IN, ev => {
        console.log(ev.message);
    });

    socket.send({
        abc: '123'
    });
});

BOS

const
    net = require('net'),
    TcpSocket = require('@mintpond/mint-socket').TcpSocket,
    BosSocket = require('@mintpond/mint-socket').BosSocket;

const server = new net.Server(netSocket => {

    const socket = new BosSocket({ netSocket: netSocket });
    socket.on(TcpSocket.EVENT_MESSAGE_IN, ev => {
        console.log(ev.message);
    });

    socket.send({
        abc: '123'
    });
});