Have a default port and only switch to a random one if that's taken
continuous-integration/drone/push Build is failing Details

This commit is contained in:
kolaente 2020-10-17 20:31:06 +02:00
parent e122ed329b
commit 36aa11d48f
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 18 additions and 0 deletions

18
portInUse.js Normal file
View File

@ -0,0 +1,18 @@
const net = require('net');
module.exports = function(port, callback) {
const server = net.createServer(function(socket) {
socket.write('Echo server\r\n');
socket.pipe(socket);
})
server.listen(port, '127.0.0.1');
server.on('error', function (e) {
callback(true)
})
server.on('listening', function (e) {
server.close()
callback(false)
})
}