# attachWebSocket

<!-- https://uncage.vercel.app/docs/api/hub/node/functions/attachwebsocket/ -->

```ts
function attachWebSocket(
   hub, 
   server, 
   o?
): () => void;
```

Defined in: hub/src/node/ws.ts:53

Accepts machine WebSockets on `server` at `path` (default `<basePath>/agent`), the traditional
mode transport; agents are offered `ws` at `path` (before `http`) until detached. Also runs `hub.maintain()` every
`maintenance.intervalMs` (default 60 s) in this long-running process. Returns a function that stops accepting new sockets
(connected machines stay until `hub.close()`); `hub.close()` detaches too. One server per hub
at a time: a second call before detaching throws.

  const server = app.listen(3000);
  attachWebSocket(hub, server);

## Parameters

| Parameter | Type |
| ------ | ------ |
| `hub` | [`Hub`](https://uncage.vercel.app/docs/api/hub/hub/interfaces/hub.md) |
| `server` | `Server` |
| `o?` | \{ `path?`: `string`; \} |
| `o.path?` | `string` |

## Returns

() => `void`
