Last active
September 23, 2025 07:02
-
-
Save kfox/1280c2f0ee8324067dba15300e0f2fd3 to your computer and use it in GitHub Desktop.
Revisions
-
kfox revised this gist
Mar 14, 2023 . No changes.There are no files selected for viewing
-
kfox revised this gist
Mar 14, 2023 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # TCP echo server for Node.js ## Usage 1. Make sure you have a modern-ish version of Node.js installed. 2. Type `npx https://gist.github.com/kfox/1280c2f0ee8324067dba15300e0f2fd3` 3. Connect to it from a client, e.g. `netcat` or similar: `nc localhost 9000` -
kfox revised this gist
Mar 14, 2023 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ { "name": "tcp-echo-server", "version": "1.0.0", "bin": "./echo.mjs" } -
kfox revised this gist
Mar 14, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ #!/usr/bin/env node import net from 'node:net' const port = process.argv[2] || 9000 -
kfox created this gist
Mar 14, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ import net from 'node:net' const port = process.argv[2] || 9000 const server = net.createServer((connection) => { const { address, port } = connection.address() const socket = `${address}:${port}` console.log(`${socket} - client connected`) connection.on('data', (data) => { console.log(`${socket} - client sent: %s`, String(data).trim()) connection.write(data) }) connection.on('end', () => { console.log(`${socket} - client disconnected`) }) }) server.listen({ port }, () => { const { address, port } = server.address() console.log('listening on %s:%d', address, port) })