Skip to content

Commit 9c22400

Browse files
committed
🤫
1 parent bae6d3c commit 9c22400

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎ws-server/index.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ expressWs(app);
1212
const broadcasters = new Set();
1313
const receivers = new Set();
1414

15+
const testEchoClients = new Set();
16+
1517
function doGC() {
1618
if (global.gc) {
1719
global.gc();
@@ -67,5 +69,25 @@ app.ws('/receive', function(ws, req) {
6769
});
6870
});
6971

72+
app.ws('/ws-test', (ws, req) => {
73+
testEchoClients.add(ws);
74+
75+
ws.on('close', () => {
76+
testEchoClients.delete(ws);
77+
});
78+
79+
ws.on('message', (message) => {
80+
testEchoClients.forEach(ec => {
81+
try {
82+
ec.send(message);
83+
//console.log(message);
84+
} catch (e) {
85+
console.log("send ws-test error : ", e);
86+
}
87+
});
88+
});
89+
90+
});
91+
7092
const port = 3344;
7193
app.listen(port, () => console.log(`WebSocket server started on ws://localhost:${port}`));

0 commit comments

Comments
 (0)