
Security News
libxml2 Maintainer Ends Embargoed Vulnerability Reports, Citing Unsustainable Burden
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
socketcluster-server
Advanced tools
Minimal server module for SocketCluster.
This is a stand-alone server module for SocketCluster. SocketCluster's protocol is backwards compatible with the SocketCluster protocol.
You will need to install both socketcluster-server
and socketcluster-client
(https://github.com/SocketCluster/socketcluster-client).
To install this module:
npm install socketcluster-server
You need to attach it to an existing Node.js http or https server (example):
const http = require('http');
const socketClusterServer = require('socketcluster-server');
let httpServer = http.createServer();
let agServer = socketClusterServer.attach(httpServer);
(async () => {
// Handle new inbound sockets.
for await (let {socket} of agServer.listener('connection')) {
(async () => {
// Set up a loop to handle and respond to RPCs for a procedure.
for await (let req of socket.procedure('customProc')) {
if (req.data.bad) {
let error = new Error('Server failed to execute the procedure');
error.name = 'BadCustomError';
req.error(error);
} else {
req.end('Success');
}
}
})();
(async () => {
// Set up a loop to handle remote transmitted events.
for await (let data of socket.receiver('customRemoteEvent')) {
// ...
}
})();
}
})();
httpServer.listen(8000);
For more detailed examples of how to use SocketCluster, see test/integration.js
.
Also, see tests from the socketcluster-client
module.
SocketCluster can work without the for-await-of
loop; a while
loop with await
statements can be used instead.
See https://github.com/SocketCluster/stream-demux#usage
For compatibility with existing SocketCluster clients, set the protocolVersion
to 1
and make sure that the path
matches your old client path:
let agServer = socketClusterServer.attach(httpServer, {
protocolVersion: 1,
path: '/socketcluster/'
});
git clone git@github.com:SocketCluster/socketcluster-server.git
cd socketcluster-server
npm install
npm test
Iterable
over EventEmitter
removeListener(...)
; just break
out of the for-await-of
loop to stop consuming. This also encourages a more declarative style of coding which reduces the likelihood of memory leaks and unintended side effects.EventEmitter
, the listener function for the same event cannot be prevented from running multiple times in parallel; also, asynchronous calls within middleware and listeners can affect the final order of actions; all this can cause unintended side effects.(The MIT License)
Copyright (c) 2013-2023 SocketCluster.io
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Server module for SocketCluster
The npm package socketcluster-server receives a total of 11,092 weekly downloads. As such, socketcluster-server popularity was classified as popular.
We found that socketcluster-server demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.