Created
April 29, 2016 21:37
-
-
Save nylen/c87fb959013f6ad3c10f11a04094f861 to your computer and use it in GitHub Desktop.
mixxx-listener.js
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
var net = require('net'); | |
var server = net.createServer(function(sock) { | |
console.log( | |
'connection from %s:%d', | |
sock.remoteAddress, sock.remotePort | |
); | |
var req = '', | |
gotHeaders = false; | |
sock.on('data', function(data) { | |
if (!gotHeaders) { | |
req += data.toString(); | |
if (req.indexOf('\r\n\r\n') >= 0) { | |
gotHeaders = true; | |
console.log(req); | |
sock.end('HTTP/1.0 200 OK\r\n\r\n'); | |
} | |
} | |
}); | |
sock.on('error', function(err) { | |
if (err.code === 'ECONNRESET' && err.syscall === 'read') { | |
// Mixxx / libshout metadata request is badly behaved? | |
} else { | |
throw err; | |
} | |
}); | |
sock.on('close', function() { | |
console.log('connection closed'); | |
}); | |
}); | |
server.listen(8888, function() { | |
console.log('listening on :8888'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment