Created
December 15, 2021 09:02
-
-
Save omranjamal/cd7c456f323514f43f68512be9ab61f4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
while : | |
do | |
echo "Attempting to connect to $1:$2 ..." | |
if exec 7<> /dev/tcp/$1/$2 ; then | |
echo "Connection Established to $1:$2" | |
while : | |
do | |
if read -u 7 TITLE && read -u 7 DESCRIPTION ; then | |
notify-send "$TITLE" "$DESCRIPTION" | |
else | |
break | |
fi | |
done | |
fi | |
echo "Connection lost. Retrying in 5 seconds ..." | |
sleep 5 | |
done |
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 net = require("net"); | |
const express = require("express"); | |
const sockets = new Set(); | |
const app = express().use(express.json()); | |
app.post("/", (req, res) => { | |
sockets.forEach((socket) => { | |
socket.write(`${req.body.title}\n${req.body.description}\n`); | |
}); | |
res.json({ | |
...req.body, | |
sentTo: sockets.size, | |
}); | |
}); | |
const server = net.createServer((socket) => { | |
sockets.add(socket); | |
socket.on("close", () => { | |
sockets.delete(socket); | |
}); | |
}); | |
server.listen(9090, "0.0.0.0", () => { | |
console.log(`Listen on 0.0.0.0:9090`); | |
}); | |
app.listen(9091, "0.0.0.0", () => { | |
console.log(`Server on http://0.0.0.0:9091`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment