Skip to content

Instantly share code, notes, and snippets.

@abeisgoat
Last active May 16, 2019 16:45
Show Gist options
  • Save abeisgoat/e3de097a1a23fb5169efdd80f67b5876 to your computer and use it in GitHub Desktop.
Save abeisgoat/e3de097a1a23fb5169efdd80f67b5876 to your computer and use it in GitHub Desktop.
const net = require("net")
const path = require("path")
const pipePath = process.platform == "win32" ? path.join('\\\\?\\pipe', process.cwd(), 'huh') : "./huh.pipe";
(async () => {
await delay(3000);
console.log("C: Attempting to connect")
const client = net.connect(pipePath);
client.on('data', function(data) {
console.log("S->C:", data.toString());
client.end();
});
client.on('end', function() {
console.log('C: client disconnected');
});
})();
function delay(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
net.createServer((client) => {
console.log('S: server connected');
client.on('end', function() {
console.log('S: server disconnected');
});
client.write('hello\r\n');
client.pipe(client);
}).listen(pipePath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment