@conflux-lib/buffer-socket
1.0.5 • Public • Published
Buffer socket
Buffer input output framework base on websocket.
Usage
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());
}
);
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:
length |
note |
4 bytes |
requestId |
N bytes |
data |
length |
note |
4 bytes |
requestId |
4 bytes |
SUCCESS |
N bytes |
data |
length |
note |
4 bytes |
requestId |
4 bytes |
ERROR |
N bytes |
error message |
Package Sidebar
Install
npm i @conflux-lib/buffer-socket
Weekly Downloads