You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
478 B
25 lines
478 B
'use strict';
|
|
const net = require('net');
|
|
|
|
module.exports = (port, options) => {
|
|
options = Object.assign({timeout: 1000}, options);
|
|
|
|
return new Promise((resolve => {
|
|
const socket = new net.Socket();
|
|
|
|
const onError = () => {
|
|
socket.destroy();
|
|
resolve(false);
|
|
};
|
|
|
|
socket.setTimeout(options.timeout);
|
|
socket.once('error', onError);
|
|
socket.once('timeout', onError);
|
|
|
|
socket.connect(port, options.host, () => {
|
|
socket.end();
|
|
resolve(true);
|
|
});
|
|
}));
|
|
};
|