We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
You can continue the conversation there. Go to discussion →
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deflate
server.js and clients.js was copied from: websockets#1369 (comment)
server.js
clients.js
'use strict'; const WebSocket = require('ws'); const message = Buffer.alloc(256); const wss = new WebSocket.Server({ port: 8080, perMessageDeflate: { zlibDeflateOptions: { memLevel: 3 }, serverMaxWindowBits: 10, threshold: 16 } }); function onClose() { if (wss.clients.size === 0) { console.log('connections: 0'); } } function broadcast() { console.log('Broadcasting message'); for (const ws of wss.clients) { ws.send(message); ws.close(); } } wss.on('connection', (ws) => { if (wss.clients.size === 1000) { console.log('connections: 1000'); broadcast(); } ws.on('close', onClose); }); wss.on('listening', function() { console.log('Listening on *:8080'); }); setInterval(function() { console.log(process.memoryUsage()); }, 10000);
'use strict'; const WebSocket = require('ws'); const total = 1000; let connected = 0; function connect() { const ws = new WebSocket('ws://localhost:8080/'); ws.on('open', function() { if (++connected < total) connect(); ws.on('close', function() { if (--connected === 0) setTimeout(connect, 5000); }); }); } connect();
Another, single file server / client test, copied from websockets#1369 (comment)
server / client
server-client.js
const WebSocket = require('ws'); const wss = new WebSocket.Server({ port: 8080, perMessageDeflate: { zlibDeflateOptions: { memLevel: 3, }, serverMaxWindowBits: 10, threshold: 16, }, }); wss.on('connection', (ws) => { ws.on('message', (message) => { ws.send(message); }); ws.on('close', () => { console.log(`close, ${wss.clients.size} listeners left`); }); }); const message = Buffer.alloc(256); function sendMessage(ws, j) { if (j < 100) { setTimeout(() => { ws.send(message, sendMessage.bind(null, ws, j + 1)); }, 16); } else { ws.close(); } } for (let i = 0; i < 1000; ++i) { const ws = new WebSocket('ws://localhost:8080/'); ws.on('open', () => { sendMessage(ws, 0); }); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
These snippets was made for testing
deflate
memory problems.server.js
andclients.js
was copied from: websockets#1369 (comment)server.js
clients.js
Another, single file
server / client
test, copied from websockets#1369 (comment)server-client.js
The text was updated successfully, but these errors were encountered: