attach(socket, index = null) {
    let idx = /** @type {number} */ (index);
    if (!this.isAddressable() || (index === null)) {
      idx = this.sockets.length;
    }
    this.sockets[idx] = socket;
    this.attachSocket(socket, idx);
    if (this.isAddressable()) {
      this.emit('attach', socket, idx);
      return;
    }
    this.emit('attach', socket);
  }
@param {import("./InternalSocket").InternalSocket} socket
@param {number|null} [index]