forked from yaemiko-sub/newtunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-ws.mjs
More file actions
28 lines (23 loc) · 712 Bytes
/
node-ws.mjs
File metadata and controls
28 lines (23 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { WebSocketServer } from 'ws';
const wss = new WebSocketServer({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('error', console.error);
ws.on('message', function message(data) {
console.log('received: %s', data);
if (data.toString() === 'close') {
console.log('---------close--------');
ws.close()
}
});
ws.on('close', () => {
console.log('-----------in close-------------close');
console.log(ws.readyState);
ws.send("xxxxxx")
ws.close()
setTimeout(() => {
console.log(ws.readyState);
ws.close()
}, 10000)
})
ws.send('something');
});