code: function monitorServerStatus(host, port, once, onChange) {
    const socket = net.connect({host, port});
    let connected = true;
    let reconnect = true;
    socket.on('connect', () => {
      connected = true;
      onChange(true);
      if (once) {
        reconnect = false;
        socket.destroy();
      }
    });
    socket.on('error', () => {});
    socket.on('close', err => {
      if (reconnect) {
        if (connected) {
          connected = false;
          onChange(false);
        }
        setTimeout(() => socket.connect({host, port}), 500);
      }
    });
    return socket;
  }
docs: Calls `onChange(connected)` callback when connection is established or closed. If `once` is true then monitoring is stopped after the first connection.