Registry / messaging / non-native-websocket

non-native-websocket

JSON →
library0.0.1jsnpmunverified

A pure JavaScript implementation of the WebSocket protocol (RFC 6455) for Node.js, supporting protocol versions 8 and 13. Current stable version is 1.0.8, released in 2012. The library includes both client and server implementations. Key differentiators: native modules are optional (fallback to JS), supports Autobahn test suite, and is one of the fastest WebSocket libraries for Node.js. Note: This package was originally published as non-native-websocket but is the precursor to the widely-used 'websocket' npm package by the same author.

npm install non-native-websocket
INSTALL
IMPORT
SIG · NON-NATIVE-WEBSOCK
N
non-native-websocket
messagingjavascriptv0.0.1
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.

WebSocketClient
✓ import { WebSocketClient } from 'non-native-websocket'
✗ var WebSocketClient = require('non-native-websocket').WebSocketClient
CommonJS require is also acceptable. The package does not ship TypeScript definitions.
WebSocketServer
✓ import { WebSocketServer } from 'non-native-websocket'
✗ const WebSocketServer = require('non-native-websocket').WebSocketServer
Both default and named exports are available. For ESM, named import is preferred.
w3cwebsocket
✓ import { w3cwebsocket } from 'non-native-websocket'
✗ const w3c = require('non-native-websocket').w3cwebsocket
This provides a W3C-compliant WebSocket client API for browsers.

Shows how to create a WebSocket server and client using the library, handling connection requests, messages, and errors.

import { WebSocketClient, WebSocketServer } from 'non-native-websocket'; // Server const serverConfig = { httpServer: require('http').createServer().listen(8080), autoAcceptConnections: false }; const wsServer = new WebSocketServer(serverConfig); wsServer.on('request', (request) => { const connection = request.accept(null, request.origin); connection.on('message', (message) => { if (message.type === 'utf8') { connection.sendUTF(message.utf8Data); } }); connection.on('close', (reasonCode, description) => { console.log('Peer disconnected'); }); }); // Client const client = new WebSocketClient(); client.on('connectFailed', (error) => console.log('Connect Error: ' + error.toString())); client.on('connect', (connection) => { connection.on('error', (error) => console.log("Connection Error: " + error.toString())); connection.on('close', () => console.log('Connection closed')); connection.on('message', (message) => { console.log("Received: " + message.utf8Data); }); connection.sendUTF('Hello'); }); client.connect('ws://localhost:8080/', null);
Debug
Known issues
breakingNative modules are optional since version 1.0.7; if compilation fails, UTF-8 validation is skipped and XOR masking is slower.
fix
No action required unless you need strict UTF-8 validation; then ensure native build tools (node-gyp) are installed or use a newer version of the library (e.g., 'websocket' package).
affects: >=1.0.7
gotchaUnicode characters outside the Basic Multilingual Plane (BMP) are truncated under Node v0.6.x due to lack of surrogate pair support.
fix
Upgrade to Node v0.8+ or use a newer library version that does not have this restriction.
affects: >=1.0.0 <1.0.7
deprecatedThis package is deprecated in favor of the 'websocket' npm package, which is the successor with the same API and active maintenance.
fix
Migrate to the 'websocket' package for continued support and updates.
affects: *
gotchaThe library does not support draft-75/draft-76/draft-00 legacy browser versions; use a different library for old browser compatibility.
fix
For legacy browser support, see https://gist.github.com/1428579 or use a polyfill.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'non-native-websocket'
The package is deprecated and may have been removed from npm or not installed correctly.
fix
Use the 'websocket' package instead: npm install websocket
Error: native module compilation failed
Missing build tools (node-gyp, python, etc.) or incompatible Node version.
fix
Install native build dependencies or use version >=1.0.7 where native modules are optional.
TypeError: Object #<Object> has no method 'sendUTF'
Incorrect usage: sendUTF is a method of the connection object, not the client.
fix
Ensure you call sendUTF on the connection object received in the 'connect' event.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies
nanoptionalOptional native addon for UTF-8 validation and efficient XOR masking; if compilation fails, pure JS fallback is used
Agent activity
20 hits · last 30 days
node
19
OpenAI (training)
1
Resources
non-native-websocket — npm install non-native-websocket · libregistry