node-two-pipe
v1.0.0
Published
Lightweight two-way named-pipe client wrapper with reconnects, heartbeat checks, send queueing, and pluggable codecs.
Readme
node-two-pipe
Two-way named-pipe client wrapper for Node.js: reconnect, heartbeat, send
queueing, JSON defaults, and pluggable codecs. The v1 public API mirrors
node-ws-pack where the transport allows it.
Install
npm i node-two-pipeUsage
import { VERSION, create } from "node-two-pipe";
const client = create({
receiver_pipe: "\\\\.\\pipe\\sdk2client",
sender_pipe: "\\\\.\\pipe\\client2sdk",
connectInterval: 2000,
reConnectInterval: 0,
heartbeat: {
ping: JSON.stringify({ id: 1, method: 100000 }),
interval: 5000,
timeoutInterval: 1000,
maxTimeoutTime: 2,
resetOnAnyMessage: true,
},
});
client.connect();
console.info("node-two-pipe", VERSION, client.currentOptions);
client.on("socketError", error => {
console.info("pipe error", error);
});
client.on("data", data => {
console.info("decoded data", data);
});
client.send({ id: 1, method: 100001, param: {} });Plain objects are JSON-stringified before sending and inbound JSON strings are
parsed. Strings and binary values are sent as-is. Use codec when the wire
protocol is not JSON.
API Notes
- Use named exports:
create,Socket, andVERSION. create(options)returns a client instance directly.connect(options?)returnstruewhen a connection attempt starts.send(data)returnstruewhen data is accepted, queued, or written.sendResult(data)exposes"queued","accepted", and"rejected".close()actively closes the current pipes and disables automatic reconnect.destroy()closes, removes listeners, and makes the instance terminal.
The old default singleton wrapper, .instance, .create, .WebSocket,
transformData, and transformResponse are not part of v1.
