Configuration
This page explains how to configure the Vix WebSocket module.
Use it when you want to control the WebSocket host, port, message limits, idle timeout, compression, ping interval, and automatic ping/pong behavior.
Header
#include <vix/websocket/config.hpp>Or use the umbrella header:
#include <vix/websocket.hpp>What configuration controls
The WebSocket module uses configuration values to control the runtime behavior of WebSocket connections.
It controls:
- bind host
- bind port
- maximum message size
- idle timeout
- per-message deflate
- heartbeat ping interval
- automatic ping/pong handling
The WebSocket config is derived from the core Vix configuration.
vix::config::Config core{".env"};
vix::websocket::Config wsConfig =
vix::websocket::Config::from_core(core);Basic .env
A minimal WebSocket configuration can look like this:
WEBSOCKET_HOST=0.0.0.0
WEBSOCKET_PORT=9090
WEBSOCKET_MAX_MESSAGE_SIZE=65536
WEBSOCKET_IDLE_TIMEOUT=60
WEBSOCKET_ENABLE_DEFLATE=true
WEBSOCKET_PING_INTERVAL=30
WEBSOCKET_AUTO_PING_PONG=trueBy default, the low-level server reads the WebSocket host from websocket.host, with 0.0.0.0 as fallback, and the WebSocket port from websocket.port, with 9090 as fallback. :contentReference[oaicite:0]
Runtime config type
The runtime configuration type is:
vix::websocket::ConfigIt contains:
struct Config
{
std::size_t maxMessageSize = 64 * 1024;
std::chrono::seconds idleTimeout{60};
bool enablePerMessageDeflate = true;
bool autoPingPong = true;
std::chrono::seconds pingInterval{30};
static Config from_core(const vix::config::Config &core);
};Default values
| Field | Default | Meaning |
|---|---|---|
maxMessageSize | 65536 | Maximum accepted WebSocket message size in bytes. |
idleTimeout | 60s | Maximum idle time before closing a connection. |
enablePerMessageDeflate | true | Enables per-message deflate support. |
autoPingPong | true | Automatically handles ping/pong behavior. |
pingInterval | 30s | Interval between heartbeat ping frames. |
Environment variables
The common environment variables are:
| Variable | Example | Purpose |
|---|---|---|
WEBSOCKET_HOST | 0.0.0.0 | Address used by the WebSocket listener. |
WEBSOCKET_PORT | 9090 | Port used by the WebSocket listener. |
WEBSOCKET_MAX_MESSAGE_SIZE | 65536 | Maximum accepted message size in bytes. |
WEBSOCKET_IDLE_TIMEOUT | 60 | Idle timeout in seconds. |
WEBSOCKET_ENABLE_DEFLATE | true | Enable per-message deflate. |
WEBSOCKET_PING_INTERVAL | 30 | Ping interval in seconds. |
WEBSOCKET_AUTO_PING_PONG | true | Automatically handle ping/pong frames. |
Host
The host controls the address where the WebSocket server binds.
WEBSOCKET_HOST=0.0.0.0Use 0.0.0.0 when the server should accept connections from available network interfaces.
For local-only development, you can use:
WEBSOCKET_HOST=127.0.0.1Common values:
| Value | Meaning |
|---|---|
0.0.0.0 | Listen on available interfaces. |
127.0.0.1 | Listen only on localhost. |
localhost | Local development host. |
Port
The port controls where clients connect.
WEBSOCKET_PORT=9090Example client URL:
ws://localhost:9090The low-level server rejects invalid ports. Ports below 1024, except 0, are treated as invalid by the current WebSocket server implementation. :contentReference[oaicite:1]
Maximum message size
The maximum message size protects the server from oversized frames.
WEBSOCKET_MAX_MESSAGE_SIZE=65536This value is read into:
Config::maxMessageSizeThe default is:
65536 bytesThat is:
64 KiBWhen the value is read from core config, the implementation enforces a minimum of 1024 bytes. :contentReference[oaicite:2]
Idle timeout
The idle timeout controls how long a connection can stay inactive before it is considered idle.
WEBSOCKET_IDLE_TIMEOUT=60This value is read into:
Config::idleTimeoutThe value is expressed in seconds.
Use 0 to disable idle timeout:
WEBSOCKET_IDLE_TIMEOUT=0When the configured value is less than or equal to 0, the runtime config stores std::chrono::seconds::zero(). :contentReference[oaicite:3]
Per-message deflate
Per-message deflate controls compression support.
WEBSOCKET_ENABLE_DEFLATE=trueThis value is read into:
Config::enablePerMessageDeflateUse false if you want to disable compression behavior:
WEBSOCKET_ENABLE_DEFLATE=falsePing interval
The ping interval controls heartbeat behavior.
WEBSOCKET_PING_INTERVAL=30This value is read into:
Config::pingIntervalThe value is expressed in seconds.
Use 0 to disable periodic ping:
WEBSOCKET_PING_INTERVAL=0When the configured value is less than or equal to 0, the runtime config stores std::chrono::seconds::zero(). :contentReference[oaicite:4]
Automatic ping/pong
Automatic ping/pong lets the runtime handle WebSocket ping and pong frames.
WEBSOCKET_AUTO_PING_PONG=trueThis value is read into:
Config::autoPingPongUse false when you want manual control:
WEBSOCKET_AUTO_PING_PONG=falseFor most applications, keep this enabled.
Load config from .env
The WebSocket server receives the core configuration object.
#include <memory>
#include <vix/config/Config.hpp>
#include <vix/executor/RuntimeExecutor.hpp>
#include <vix/websocket.hpp>
int main()
{
vix::config::Config config{".env"};
auto executor =
std::make_shared<vix::executor::RuntimeExecutor>(4);
vix::websocket::Server ws{config, executor};
ws.start();
return 0;
}Derive WebSocket config manually
You can derive the WebSocket runtime config manually when you need to inspect the final values.
#include <vix/config/Config.hpp>
#include <vix/print.hpp>
#include <vix/websocket/config.hpp>
int main()
{
vix::config::Config core{".env"};
vix::websocket::Config ws =
vix::websocket::Config::from_core(core);
vix::print("max message size:", ws.maxMessageSize);
vix::print("idle timeout:", ws.idleTimeout.count());
vix::print("ping interval:", ws.pingInterval.count());
return 0;
}Configuration in attached runtime
When WebSocket is attached to an HTTP app, the WebSocket server can reuse the app configuration.
#include <memory>
#include <vix.hpp>
#include <vix/websocket.hpp>
int main()
{
vix::App app;
auto executor =
std::make_shared<vix::executor::RuntimeExecutor>(4);
vix::websocket::Server ws{app.config(), executor};
vix::websocket::AttachedRuntime runtime{app, ws, executor};
app.run(8080);
return 0;
}In this model:
vix::App
-> owns core config
vix::websocket::Server
-> reads WebSocket config from app.config()Example production .env
# HTTP
SERVER_PORT=8080
SERVER_IO_THREADS=0
SERVER_REQUEST_TIMEOUT=2000
SERVER_SESSION_TIMEOUT_SEC=20
# WebSocket
WEBSOCKET_HOST=0.0.0.0
WEBSOCKET_PORT=9090
WEBSOCKET_MAX_MESSAGE_SIZE=65536
WEBSOCKET_IDLE_TIMEOUT=60
WEBSOCKET_ENABLE_DEFLATE=true
WEBSOCKET_PING_INTERVAL=30
WEBSOCKET_AUTO_PING_PONG=true
# Logging
LOGGING_ASYNC=true
LOGGING_QUEUE_MAX=20000
LOGGING_DROP_ON_OVERFLOW=trueRecommended defaults
For most applications, start with:
WEBSOCKET_HOST=0.0.0.0
WEBSOCKET_PORT=9090
WEBSOCKET_MAX_MESSAGE_SIZE=65536
WEBSOCKET_IDLE_TIMEOUT=60
WEBSOCKET_ENABLE_DEFLATE=true
WEBSOCKET_PING_INTERVAL=30
WEBSOCKET_AUTO_PING_PONG=trueThese defaults are good for:
- chat
- notifications
- dashboards
- local agents
- browser clients
- realtime application events
Larger messages
If your application sends larger JSON payloads, increase the maximum message size.
WEBSOCKET_MAX_MESSAGE_SIZE=262144This allows messages up to:
256 KiBBe careful with very large message limits. WebSocket is best for realtime messages, not large file transfers.
For large files, prefer HTTP upload or a dedicated storage flow.
Shorter heartbeat
If you want faster detection of dead connections, reduce the ping interval.
WEBSOCKET_PING_INTERVAL=10This sends heartbeat pings more often.
Use this for:
- realtime dashboards
- presence tracking
- chat presence
- low-latency connection monitoring
Longer idle timeout
If your users may stay connected but inactive for a long time, increase the idle timeout.
WEBSOCKET_IDLE_TIMEOUT=300This allows inactive connections to remain open for five minutes.
Disable idle timeout
For local development or controlled internal services:
WEBSOCKET_IDLE_TIMEOUT=0This disables idle timeout behavior.
Do not use this blindly in public production systems unless you also have other connection limits.
Disable compression
Compression can reduce bandwidth but may add CPU cost.
Disable it when:
- messages are already small
- CPU is more important than bandwidth
- you want simpler behavior during debugging
WEBSOCKET_ENABLE_DEFLATE=falseDisable auto ping/pong
Most applications should keep automatic ping/pong enabled.
Disable it only if you are implementing custom heartbeat behavior.
WEBSOCKET_AUTO_PING_PONG=falseConfiguration flow
The configuration flow is:
.env
-> vix::config::Config
-> vix::websocket::Config::from_core(...)
-> LowLevelServer
-> SessionThe server uses the core config for host and port.
The WebSocket runtime config controls per-session protocol behavior.
Common issues
Server does not accept external connections
Check the host.
WEBSOCKET_HOST=0.0.0.0If the host is 127.0.0.1, only local connections can connect.
Browser cannot connect
Check the URL:
ws://localhost:9090Also verify the port:
WEBSOCKET_PORT=9090Messages are rejected or connection closes
Check the message size:
WEBSOCKET_MAX_MESSAGE_SIZE=65536If your payload is bigger than the configured limit, increase the limit carefully.
Idle clients disconnect
Check the idle timeout:
WEBSOCKET_IDLE_TIMEOUT=60Increase it or set it to 0 for development.
Heartbeat is too slow
Reduce the ping interval:
WEBSOCKET_PING_INTERVAL=10Heartbeat is disabled
Check that the ping interval is greater than 0:
WEBSOCKET_PING_INTERVAL=30Next steps
Continue with: