Package Exports
- presidium-websocket
- presidium-websocket/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (presidium-websocket) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
presidium-websocket
Presidium WebSocket
WebSocket client and server for Node.js.
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 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(1337, () => {
console.log('WebSocket Secure server listening on port 1337')
})
const websocket = new WebSocket('wss://localhost:1337/')
websocket.on('open', () => {
websocket.send('Hello from client!')
})
websocket.on('message', message => {
console.log('Message from server:', message)
})Installation
with npm
npm i presidium-websocketBenchmarks
Please find the published benchmark output inside the benchmark-output folder. You can run the benchmarks on your own system with the following command:
npm run benchLicense
Presidium WebSocket is MIT Licensed.
Support
- minimum Node.js version: 16