There is some way to catch if the socket server I'm trying to connect to is (off, not available etc.).
This is my code:
import http from 'http';
import socket_io from 'socket.io';
In the event of my button
try{
var net = require('net');
var client = net.connect(12346, 'localhost');
client.setEncoding('utf8');
client.on('data', function(data) {
console.log("Recibiendo :", arguments)
});
client.on('disconnect', function() {
console.log("Error al conectarme con el servido");
});
client.on('end', () => {
console.log('desconectado del servidor');
});
client.on('close', function() {
console.log('Conexion cerrada');
});
}catch(error) {
console.log("Error al conectarme con el servidor :"+error);
}
I have no problems when I run the server, but if the socket server is stopped or I have not started it, it does not show any of my logs and the app corrupts showing me the message:
connect ECONNREFUSED 127.0.0.1:12346 and
TCPConnectWrap.afterConnect [as oncomplete]