Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
npm install websockets
require websockets
var websockets = require("websockets");
Server is a wrapper of http/https
server.
// http based server
var server = websockets.createServer();
server.on('connect', function(socket) {
socket.on('message', function(message) {
socket.send('echo a message:' + message);
......
});
}).listen(80);
// https based server
var secure = websockets.createServer({
key: ssl_key,
cert: ssl_cert
});
secure.on('connect', function(socket) {
......
}).listen(443);
Extended Servers such as express are also available.
// In case of 'express'
var express = require('express');
var svr = express.createServer();
svr.get('/', function(req, res) {
......
});
svr.configure(function() {
......
});
var server = websockets.createServer({
server: svr
});
server.on('connect', function(socket) {
socket.on('message', function(message) {
socket.send('echo a message:' + message);
......
});
}).listen(80);
Client has the interfaces like html5 WebSocket.
var socket = new websockets.WebSocket('wss://127.0.0.1');
socket.on('open', function() {
socket.send('a message');
......
});
function (socket) {}
Emitted when client-server opening handshake has succeeded. socket
is an instance of WebSocket
.
Not Implemented.
Sends string
to all clients connected with server
.
Not Implemented.
Sends binary data(buffer
) to all clients connected with server
.
function () {}
Emitted when a client-server connection is successfully established.
function (data) {}
Emitted when the socket has received a message. The type of data
is either string
(string data) or Buffer
(binary data).
function (exception) {}
Emitted on error. exception
is an instance of Error.
function () {}
Emitted when a client-server connection has closed.
Sends string
to the other endpoint.
Sends binary data(buffer
) to the other endpoint.
Sends a connection close request to the other endpoint.
FAQs
WebSocket Server & Client API
We found that websockets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.