Created
April 14, 2020 09:04
-
-
Save yurivm/98e730e356f6106075a0ba2697b4637d to your computer and use it in GitHub Desktop.
mumble_loop.js
This file contains hidden or 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 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