# Connection

> The client opens exactly one connection to the server, for the life of the container; the begin scope comes first and once, every mount of the request before the rest and any further mount at any time after; the connection ending ends every scope on it, and nothing is re-asked.

Canonical: https://protocol.diverge.network/2.3.0/container-proxy/connection/
Specification revision: 2.3.0

The client opens the connection, and the connection is the life of
the container: every scope the client opens rides it, in the order
this page states, and nothing survives it.

- **The opening.** The client performs the WebSocket opening handshake
  against port `14979` of the container, at the path `/`. The server
  sends no frame before the client's first frame.
- **One connection.** The server accepts exactly one connection in its
  life. It refuses every later upgrade with HTTP status `409` before
  the upgrade, whether the first connection is open or has ended.
  There is no second connection to a proxy.
- **The first frame.** The first frame the client sends is a request,
  type `1`, opening the begin scope of the container's family:
  [agents::begin](/2.3.0/container-proxy-endpoints/agents-begin/) on an
  agent container, [tools::begin](/2.3.0/container-proxy-endpoints/tools-begin/)
  on a tool container. The client sends it exactly once on the
  connection and before any other request. A second begin is answered
  by exactly one error response and the response finish, and the
  first begin continues.
- **The mounts.** After the begin has been answered, the client opens
  one [fuse::mount](/2.3.0/container-proxy-endpoints/fuse-mount/) scope per
  mount of the container's request, and opens no other scope until
  every one of them has been answered. After that the client opens a
  further mount scope at any time, for the life of the connection,
  beside whatever other scopes are open; the server serves one
  opened then as it serves one opened before.
- **The rest.** After every mount of the request has been answered, the client opens
  [filesystem::tree](/2.3.0/container-proxy-endpoints/filesystem-tree/),
  [filesystem::read](/2.3.0/container-proxy-endpoints/filesystem-read/) and
  [filesystem::write](/2.3.0/container-proxy-endpoints/filesystem-write/)
  scopes, and channels on the begin scope, in any order and in
  parallel. Neither party opens a channel on the begin scope before
  the server has sent its `Begun` response.
- **The end.** The connection ends when either party closes it, by
  the WebSocket closing handshake or otherwise. When it ends, every
  scope on it is over and every channel with it, without a finish.
  The server re-asks nothing that was in flight, and the client
  re-sends nothing: what was in flight when the connection ended is
  what was in flight when the container ended.
- **The server does not close.** The server closes the connection
  only on a frame of type `0`. It does not close the connection on a
  frame it cannot read, on a request it cannot read, on a scope it
  cannot serve, or after any length of quiet.
