websocket-driver
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
http-parser-js | 0.5.8 | 7.43 kB | MIT | prod | |
safe-buffer | 5.2.1 | 9.74 kB | MIT | prod | |
websocket-extensions | 0.1.4 | 15.33 kB | Apache-2.0 | prod |
WebSocket-Driver is an npm module that acts as an implementation of the WebSocket protocols and is capable of connecting to any I/O stream. The primary function is to simplify the WebSocket protocol interaction by taking care of the protocol details; this makes it easy for users to focus on building and implementing functionality that solely relies on data streaming, without being concerned about the intricacies of the protocol details.
The WebSocket-Driver module can be easily installed and incorporated into your project using the npm command npm install websocket-driver
. After installation, it can used in a variety of scenarios, with examples given below:
Server-side with HTTP:
var http = require('http'),
websocket = require('websocket-driver');
var server = http.createServer();
server.on('upgrade', function(request, socket, body) {
if (!websocket.isWebSocket(request)) return;
var driver = websocket.http(request);
driver.io.write(body);
socket.pipe(driver.io).pipe(socket);
driver.messages.on('data', function(message) {
console.log('Got a message', message);
});
driver.start();
});
Server-side with TCP:
var net = require('net'),
websocket = require('websocket-driver');
var server = net.createServer(function(connection) {
var driver = websocket.server();
//... rest of the code
});
Client-side implementation:
var net = require('net'),
websocket = require('websocket-driver');
var driver = websocket.client('ws://www.example.com/socket'),
tcp = net.connect(80, 'www.example.com');
tcp.pipe(driver.io).pipe(tcp);
tcp.on('connect', function() {
driver.start();
});
driver.messages.on('data', function(message) {
console.log('Got a message', message);
});
For HTTP Proxies, Driver API and more, users can refer to the provided examples in the readme file on the Github repository of the module.
The full documentation and extensive details on the usage of WebSocket-Driver npm package are available provided directly within the readme on the official GitHub repository for this package. It contains examples of how to use the package in various scenarios along with insights on interacting with the driver API. To additional read documentation for WebSocket-Driver can follow the link git://github.com/faye/websocket-driver-node.git.