This repository has been archived on 2026-05-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
instructions-clear/tools/fake-clients.js
T

24 lines
637 B
JavaScript

import WebSocket from 'ws'
const numberOfClients = 10
const url = 'ws://localhost:1280/ws'
for (let i = 1; i <= numberOfClients; i++) {
const id = `${i}`
const websocket = new WebSocket(url)
websocket.onerror = () => websocket.close()
websocket.onopen = () => {
websocket.send(JSON.stringify({ action: 'join', id }))
console.log({ client: id, event: 'joined' })
}
websocket.onclose = () => {
console.log({ client: id, event: 'disconnected' })
}
websocket.onmessage = (event) => {
const byteSize = new Blob([event.data]).size
// console.log({ client: id, received: `${byteSize} B of data` })
}
}