Last active
May 16, 2019 16:45
-
-
Save abeisgoat/e3de097a1a23fb5169efdd80f67b5876 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
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