Skip to content

Instantly share code, notes, and snippets.

@yurivm
Created April 14, 2020 09:04
Show Gist options
  • Select an option

  • Save yurivm/98e730e356f6106075a0ba2697b4637d to your computer and use it in GitHub Desktop.

Select an option

Save yurivm/98e730e356f6106075a0ba2697b4637d to your computer and use it in GitHub Desktop.
mumble_loop.js
const net = require('net');
const clients = [];
function handleConnection(conn) {
function onConnData(d) {
const decoder = new StringDecoder();
// Decode received string
const stream = decoder.write(d);
try {
splitJson(stream).forEach((str) => clients.forEach((client) => client.send(str)));
} catch (err) {
console.log('Error sending data: %s', err);
}
}
// error handling removed here for brevity
conn.on('data', onConnData);
}
const server = net.createServer();
server.on('connection', handleConnection);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment