Commit | Line | Data |
---|---|---|
219d4044 JB |
1 | import { WebSocket } from 'ws' |
2 | ||
3 | const ws = new WebSocket('ws://localhost:8080') | |
4 | ||
5 | ws.on('error', console.error) | |
6 | ||
7 | ws.on('open', () => { | |
8 | for (let i = 0; i < 60; i++) { | |
9 | ws.send( | |
10 | JSON.stringify({ type: 'echo', data: { key1: 'value1', key2: 'value2' } }) | |
11 | ) | |
12 | } | |
13 | for (let i = 0; i < 60; i++) { | |
66f0c14c | 14 | ws.send(JSON.stringify({ type: 'factorial', data: { number: 50000 } })) |
219d4044 JB |
15 | } |
16 | }) | |
17 | ||
041dc05b | 18 | ws.on('message', message => { |
219d4044 JB |
19 | console.info('message received: %s', message) |
20 | }) |