presidium-websocket
v4.1.0
Published
Presidium WebSocket client and server
Maintainers
Readme
Presidium WebSocket

Source code: GitHub | License: CFOSS
Presidium WebSocket client and server. Implements RFC 6455 and RFC 7692.
const WebSocket = require('presidium-websocket')
const server = new WebSocket.Server(websocket => {
websocket.on('message', message => {
console.log('Message from client:', message)
websocket.send('Hello from server!')
})
websocket.on('close', () => {
console.log('websocket closed')
})
})
server.listen(1337, () => {
console.log('WebSocket server listening on port 1337')
})
const websocket = new WebSocket('ws://localhost:1337/')
websocket.on('open', () => {
websocket.send('Hello from client!')
})
websocket.on('message', message => {
console.log('Message from server:', message)
})Serve WebSocket Secure (WSS) connections.
const WebSocket = require('presidium-websocket')
const fs = require('fs')
const server = new WebSocket.SecureServer({
key: fs.readFileSync('/path/to/my-key'),
cert: fs.readFileSync('/path/to/my-cert')
})
server.on('connection', websocket => {
websocket.on('message', message => {
console.log('Secure message from client:', message)
websocket.send('Hello from server!')
})
websocket.on('close', () => {
console.log('websocket closed')
})
})
server.listen(4443, () => {
console.log('WebSocket Secure server listening on port 4443')
})
const websocket = new WebSocket('wss://localhost:4443/')
websocket.on('open', () => {
websocket.send('Hello from client!')
})
websocket.on('message', message => {
console.log('Message from server:', message)
})Supports Compression Extensions for WebSocket with supportPerMessageDeflate (uses zlib default options).
const server = new WebSocket.Server({ supportPerMessageDeflate: true })Initiate new connections on the same websocket instance.
const websocket = new WebSocket('ws://localhost:1337/')
// reconnect websocket on broken connections
while (true) {
if (websocket.readyState === 1) {
// websocket is open
} else {
// reconnect
websocket.connect()
}
await sleep(10000)
}Docs
Please find the full documentation for the Presidium library at presidium.services.
Presidium WebSocket class documentation:
Installation
with npm:
npm i presidium-websocketBenchmarks
Please find all of the published benchmark output inside the benchmark-output folder.
v4.1.0 Small Message Bo10 Best Run:
Time: 30.086919502 seconds
Presidium throughput: 822.4584191295062 messages/s
Presidium messages: 24694Running benchmarks on your own system
Run benchmarks for presidium-websocket:
./bench-presidiumLicense
Presidium WebSocket is distributed under the CFOSS License.
Support
- minimum Node.js version: 16
