# BaseSocketServer

> Documentation for Redweb 0.16.1. Install that exact version when following these examples.

Shared lifecycle and route-composition base for SocketServer and SecureSocketServer. Prefer defineApp for application startup; use concrete server classes or this base for infrastructure integrations.

## Explain it like I’m five

BaseSocketServer is the engine room beneath both plain and secure socket servers. It coordinates routes and upgrades without deciding how the outer listener was created.

## When should I use it?

Use this advanced surface for custom integrations that need Redweb routing on a specially managed Node HTTP or HTTPS server.

## Follow the example

This API pattern illustrates the named surface; it may require application-owned classes, credentials, or assets. Start from a complete recipe for a runnable application.

```js
import { BaseSocketServer } from 'redweb'

// SocketServer and SecureSocketServer inherit:
// addRoute(), handleUpgrade(), beginDrain(), and shutdown().
```

1. Your application supplies or prepares the listener.
2. BaseSocketServer attaches bounded WebSocket upgrade and route lifecycle behavior.
3. Concrete server ownership remains visible, including whether Redweb may listen or close it.

## Methods and members

### addRoute(RouteClass)

Creates and registers one route class while enforcing unique paths.

### beginDrain()

Stops accepting new upgrades across every registered route.

### shutdown()

Drains routes and closes owned listeners without closing caller-owned servers.

## What should I watch for?

Most applications should use defineApp. Reach for lower-level servers only when listener ownership needs a custom integration.
