WebSocket · In depth

SecureSocketServer

HTTPS + WebSocket pairing. Mirrors `SocketServer` but wraps an HTTPS server built from the provided TLS files.

Explain it like I’m five

The simple mental model

SecureSocketServer is the encrypted version of the WebSocket switchboard: clients use wss:// and the connection stays protected from the first handshake onward.

When it fits

When should I use it?

Use it when Redweb directly owns a TLS WebSocket listener rather than sharing an externally terminated HTTPS connection.

A practical API pattern

Follow the example

This pattern explains the named API. Application classes, credentials, and assets may need to be supplied; use a complete recipe for a runnable starting point.

Read this article as Markdown

JavaScript
const { SecureSocketServer } = require('redweb')
const { GameRoute } = require('./routes/GameRoute')

new SecureSocketServer({
  port: 3443,
  ssl: { key: './certs/dev.key', cert: './certs/dev.crt' },
  routes: [GameRoute],
})
  1. 1

    TLS material is loaded to create or configure the HTTPS listener.

  2. 2

    WebSocket upgrades travel through the same route selection used by SocketServer.

  3. 3

    Route handlers see ordinary Redweb sockets after the secure handshake completes.

Configuration

Choices you can make

  • port: number (default 3000)
  • listen: boolean (default true for owned servers); supplied servers do not listen unless explicitly true
  • server: existing https.Server to attach to without double-listening (optional)
  • ssl.key and ssl.cert: required file paths
  • routes: array of SocketRoute subclasses
Surface area

Methods and members

constructor(options)

Loads TLS files or reuses a supplied HTTPS server, registers the provided routes, attaches upgrade handling, and starts listening only when Redweb owns the server or listen is explicitly true.

addRoute(RouteClass)

Same runtime route attachment as `SocketServer`.

shutdown()

Stops routes, services, and the HTTPS listener.