Browse Source

Have a default port and only switch to a random one if that's taken

pull/1/head
kolaente 8 months ago
parent
commit
36aa11d48f
Signed by: konrad GPG Key ID: F40E70337AB24C9B
  1. 18
      portInUse.js

18
portInUse.js

@ -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)
})
}
Loading…
Cancel
Save