Created
June 27, 2017 20:03
-
-
Save rwaldron/b03a91a38de6c438efcbecfd739c1b11 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
"use strict"; | |
const net = require("net"); | |
const monitor = { | |
connection: null, | |
queue: [], | |
write() { | |
if (monitor.connection === null) { | |
monitor.queue.push(arguments); | |
} else { | |
monitor.connection.write.apply(monitor.connection, arguments); | |
} | |
} | |
}; | |
const server = net.createServer((c) => { | |
monitor.connection = c; | |
c.on("end", () => { | |
monitor.connection = null; | |
}); | |
if (monitor.queue.length) { | |
let message; | |
while (message = monitor.queue.shift()) { | |
monitor.connection.write.apply(monitor.connection, message); | |
} | |
} | |
c.pipe(c); | |
}); | |
server.listen(8124); | |
// Write will queue all messages and send them | |
// once a remote client connection is made. | |
// Once connected, new messages will be sent directly | |
monitor.write("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 net = require("net"); | |
const client = net.createConnection({ host: "your-tessel-name.local", port: 8124 }, () => { | |
console.log("Connected to Tessel..."); | |
}); | |
client.on("data", (data) => { | |
console.log(data.toString()); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment