1.0.5 • Published 3 years ago

@conflux-lib/buffer-socket v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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:
lengthnote
4 bytesrequestId
N bytesdata
  • response:
lengthnote
4 bytesrequestId
4 bytesSUCCESS
N bytesdata
  • error:
lengthnote
4 bytesrequestId
4 bytesERROR
N byteserror message