@dev-tanaay/live-wire
v1.0.0
Published
WebSocket
Downloads
6
Readme
LiveWire
High-performance WebSocket implementation from scratch.
No libraries, no ws, no socket.io. Built directly on raw TCP using Node.js net module and RFC 6455.
Overview
LiveWire is a ground-up implementation of the WebSocket protocol. It was born from a desire to understand exactly how bytes travel across the wire during a WebSocket connection.
Features
- Raw TCP Handshake: Manual parsing of HTTP "Upgrade" headers.
- RFC 6455 Compliant Framing: Full support for FIN bits, Opcodes, and Masking.
- Payload Management: Handles small, medium, and large (64-bit) payloads.
- Fragmentation: Reassembles fragmented frames into complete messages.
- Control Frames: Native support for PING/PONG heartbeats and Graceful Close.
- Broadcast Engine: Built-in multi-client management for real-time applications.
- Generic Protocol: Send raw strings or structured JSON with ease.
Installation
To use LiveWire in your own project:
npm install live-wireUsage
Basic Server
import { LiveWireServer } from "live-wire";
const server = new LiveWireServer();
server.on("connection", (ws) => {
console.log("A new client joined!");
ws.on("message", (data) => {
console.log("Received:", data);
// Broadcast to everyone
server.broadcast({
type: "chat",
message: data
});
});
});
server.listen(5000, () => {
console.log("LiveWire Server running on port 5000");
});Architecture
LiveWire is modularly designed:
LiveWireServer: Orchestrates the TCP server and the HTTP -> WebSocket upgrade handshake.LiveWire: Encapsulates a single client connection, handling the framing and unmasking of packets.
Author
Built as a deep-dive into networking protocols. Feel free to use it for your own learning or to power lightweight real-time apps!
