@conflux-lib/buffer-socket

1.0.5 • Public • Published

Buffer socket

Buffer input output framework base on websocket.

Usage

  • server
const { Server, Client } = require('@conflux-lib/buffer-socket');

const server = new Server(
  { host: '127.0.0.1', port: 6080, checkAliveInterval:30*1000 }, 
  (input, output) =>{
    output.write(input.toBuffer().reverse());
  }
);
  • client
const client = new Client({ host: '127.0.0.1', port: 6080 });

const stream = await client.request(Buffer.from('1234'));

console.log(stream.toBuffer().toString()); // 4321

Package structure:

  • request:
length note
4 bytes requestId
N bytes data
  • response:
length note
4 bytes requestId
4 bytes SUCCESS
N bytes data
  • error:
length note
4 bytes requestId
4 bytes ERROR
N bytes error message

Readme

Keywords

Package Sidebar

Install

npm i @conflux-lib/buffer-socket

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

13.8 kB

Total Files

9

Last publish

Collaborators

  • zhentingwang