Created
December 29, 2023 13:28
-
-
Save luckasRanarison/8856b5e0d8354b4b92387cf05860214b to your computer and use it in GitHub Desktop.
hello-UDS-node
This file contains 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 characters
echo "Hello world!" | nc -U /tmp/test-socket/socket.sock | |
# Hi! |
This file contains 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 characters
const fs = require("fs"); | |
const net = require("net"); | |
const SOCKET_PATH = "/tmp/test-socket"; | |
if (fs.existsSync(SOCKET_PATH)) { | |
fs.rmSync(SOCKET_PATH, { recursive: true, force: true }); | |
} | |
fs.mkdirSync(SOCKET_PATH); | |
const server = net.createServer((socket) => { | |
socket.on("data", (data) => { | |
console.log(data.toString()); | |
socket.write("Hi!"); | |
socket.end(); | |
}); | |
}); | |
server.listen(SOCKET_PATH + "/socket.sock", () => { | |
console.log(`Listening on ${SOCKET_PATH}/socket.sock`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment