Registry / devops / madsocket

madsocket

JSON →
library2.4.2jsnpmunverified

A lightweight WebSocket server implementation for Node.js. Version 2.4.2 is the latest stable release, with infrequent updates. Provides a simple event-driven API for handling WebSocket connections, supporting both direct server listening and sharing a port with an existing HTTP server via the `leech` method. Key differentiators: minimalistic design, explicit listener object pattern, and support for both direct and piggyback server modes. No external dependencies.

npm install madsocket
INSTALL
IMPORT
SIG · MADSOCKET
M
madsocket
devopsjavascriptv2.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MadSocket
import MadSocket from 'madsocket'
const { MadSocket } = require('madsocket')
Default export in ESM. CommonJS users use require('madsocket') directly.
MadSocket (type)
import type MadSocket from 'madsocket'
import { MadSocket } from 'madsocket'
TypeScript users should use `import type` for type-only imports.
ClientConnection
import MadSocket from 'madsocket'; // ClientConnection is internal type
import { ClientConnection } from 'madsocket'
ClientConnection is not exported; it's only accessible via `this` in event listeners.

Shows complete setup: create server instance with event listeners, start listening on port 8080, handle messages and errors, and graceful shutdown.

import MadSocket from 'madsocket'; const ws = new MadSocket({ start: () => { console.log('Server started'); }, connect: () => { console.log('Client connected'); }, message: (msg) => { console.log('Received:', msg); this.send('Echo: ' + msg); }, disconnect: () => { console.log('Client disconnected'); }, error: (err) => { console.error('Error:', err); } }, { timeout: 0 }); ws.listen(8080, '0.0.0.0'); // Graceful shutdown process.on('SIGINT', () => { ws.close(); });
Debug
Known issues
breakingVersion 2.x changed constructor signature from `new MadSocket(port, listeners, props)` to `new MadSocket(listeners, props)`
fix
Pass listeners as first argument, props as second. Remove port from constructor; use .listen() instead.
affects: >=2.0.0 <2.0.0
gotchaThe `leech` method requires Node.js v10+ for HTTP server connection event; older versions must use 'upgrade' event
fix
For Node <10, attach leech to 'upgrade' event: `server.on('upgrade', (req, socket) => ws.leech(req, socket))`.
affects: <10.0.0
gotchaWhen using http.createServer, do NOT call ws.leech inside both 'connection' and 'upgrade' events to avoid double processing
fix
Choose one approach: either use 'connection' event for Node v10+ or 'upgrade' event for older versions, not both.
affects: >=2.0.0
gotchaTimeout property in props sets idle timeout per socket; default 0 means no timeout (infinite idle allowed)
fix
Set timeout to a positive number (milliseconds) to auto-close idle sockets.
affects: >=2.0.0
gotchaEvent listeners must be object functions; arrow functions will not have correct 'this' context
fix
Use regular functions (not arrow functions) for listeners to access ClientConnection via 'this'.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: MadSocket is not a constructor
Using named import instead of default import in ESM
fix
Use `import MadSocket from 'madsocket'` instead of `import { MadSocket } from 'madsocket'`
ReferenceError: this is undefined
Using arrow function for event listener
fix
Replace arrow function with regular function: `message: function(msg) { ... }`
Error: listen EADDRINUSE :::8080
Port already in use
fix
Choose a different port or kill the process using the port
TypeError: ws.leech is not a function
Using outdated version (<2.0) where leech didn't exist
fix
Upgrade to madsocket@2.4.2
Upgrade
Version history
2.4.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
madsocket — npm install madsocket · libregistry