WebSocket echo for testing laptop tunnels
This commit is contained in:
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
Generated
+39
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "ws-echo",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ws-echo",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"ws": "8.18.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.18.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
|
||||
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "ws-echo",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "server.js",
|
||||
"scripts": { "start": "node server.js" },
|
||||
"engines": { "node": ">=20" },
|
||||
"dependencies": { "ws": "8.18.3" }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WebSocket echo for testing deployshed's laptop tunnel: echoes each message
|
||||
// and pushes a tick every 5 s so a long-lived connection is visible.
|
||||
const http = require('http');
|
||||
const { WebSocketServer } = require('ws');
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
res.end('ws-echo: connect with a WebSocket to this address\n');
|
||||
});
|
||||
const wss = new WebSocketServer({ server });
|
||||
wss.on('connection', (ws) => {
|
||||
ws.send('hello');
|
||||
ws.on('message', (m) => ws.send('echo:' + m));
|
||||
const t = setInterval(() => ws.send('tick:' + Date.now()), 5000);
|
||||
ws.on('close', () => clearInterval(t));
|
||||
});
|
||||
server.listen(process.env.PORT || 8080);
|
||||
Reference in New Issue
Block a user