function connectPort(socket, process, port, index, inbound) {
  if (inbound) {
    socket.to = {
      process,
      port,
      index,
    };

    if (!process.component
      || !process.component.inPorts
      || !process.component.inPorts.ports[port]) {
      return Promise.reject(new Error(`No inport '${port}' defined in process ${process.id} (${socket.getId()})`));
    }
    if (process.component.inPorts.ports[port].isAddressable()) {
      process.component.inPorts.ports[port].attach(socket, index);
      return Promise.resolve(socket);
    }
    process.component.inPorts.ports[port].attach(socket);
    return Promise.resolve(socket);
  }

  socket.from = {
    process,
    port,
    index,
  };

  if (!process.component
    || !process.component.outPorts
    || !process.component.outPorts.ports[port]) {
    return Promise.reject(new Error(`No outport '${port}' defined in process ${process.id} (${socket.getId()})`));
  }

  if (process.component.outPorts.ports[port].isAddressable()) {
    process.component.outPorts.ports[port].attach(socket, index);
    return Promise.resolve(socket);
  }
  process.component.outPorts.ports[port].attach(socket);
  return Promise.resolve(socket);
}
@param {internalSocket.InternalSocket} socket
@param {NetworkProcess} process
@param {string} port
@param {number|null} index
@param {boolean} inbound
@returns {Promise<internalSocket.InternalSocket>}