Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 28ce72ca rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Correct way to ping

parent e01af4d4
Branches
Aucune étiquette associée trouvée
1 requête de fusion!12Config and signals refactor
......@@ -39,7 +39,7 @@ class LktClient {
});
this.m_socket.on('ready', () => {
logger.debug('lkt', `Ready to use socker with localhost:${config.port}`);
logger.debug('lkt', `Ready to use socket with localhost:${config.port}`);
this.m_online = true;
});
......@@ -284,7 +284,49 @@ class LktClient {
}
static ping() {
return LktClient.__execSimple('ping');
var socket = new net.Socket();
var result = {};
function __getResult(socket) {
return new Promise(resolv => {
const sockopt = {
port: config.port,
host: config.host,
readable: true,
writable: true,
};
logger.debug('lkt', 'Try to ping');
socket.setTimeout(3000);
socket.setEncoding('utf8');
socket.on('timeout', () => {
logger.error('lkt', `Got timeout while ping to localhost:${config.port}`);
result = false;
resolv(result);
});
socket.on('ready', () => {
logger.debug('lkt', `Ping success with localhost:${config.port}`);
result = true;
resolv(result);
});
socket.on('error', err => {
logger.error('lkt', `${err}`);
result = false;
resolv(result);
});
socket.connect(sockopt, () => {
logger.info('lkt', `Pinged localhost:${config.port}`);
socket.destroy();
result = true;
resolv(result);
});
});
}
return __getResult(socket);
}
}
......
......@@ -287,7 +287,8 @@ ipcMain.on('verify-state', (event, arg) => {
});
ipcMain.on('verify-lektord', (event, arg) => {
lkt.ping().then(data => {
lkt.ping().then(sta => {
logger.debug('main', `Status from ping is ${sta}`);
lkt.reloadState();
event.reply('send-lektord');
});
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter