WebSocket Real-Time Server
Relevant source files
The following files were used as context for generating this wiki page:
The WebSocket Real-Time Server is a critical infrastructure component of the TAMV Online ecosystem. Its primary purpose is to maintain persistent, bidirectional communication channels between the central management system and various active nodes, including mobile tracking units, administrative consoles, and client monitoring interfaces. This enables the "ambitious" real-time synchronization capabilities required for modern logistics and vehicle management.
Within the scope of the project, the WebSocket server acts as the central hub for event-driven updates. It ensures that any change in the state of the system—such as location updates, status changes, or emergency alerts—is propagated across the network with minimal latency, moving away from traditional polling-based architectures.
Sources: README.md:1-2, Documentación Técnica TAMV Online.pdf
Architecture and Connection Lifecycle
The server utilizes a stateful architecture to maintain the inventory of active connections. Upon a client request, the server performs a protocol upgrade from HTTP to WS (WebSocket), establishing a dedicated tunnel for continuous data flow.
Connection Flow
The following sequence diagram illustrates the lifecycle of a WebSocket connection within the TAMV Online environment, from initial handshake to active data exchange.
The diagram shows the transition from a standard request to a persistent state, highlighting the integrated authentication step required for secure data transmission.
Sources: Documentación Técnica TAMV Online.pdf, Diagrama de flujo TAMV Online.png
Real-Time Data Flow and Event Handling
The server processes incoming streams of data (Ingress) and distributes them to relevant subscribers (Egress). In the context of TAMV Online, this primarily involves tracking telemetry and operational commands.
Event Distribution Logic
When a tracking unit transmits a new coordinate, the server performs the following actions:
- Validation: Verifies the integrity of the JSON payload.
- Persistence: Asynchronously triggers a database write.
- Broadcasting: Identifies connected clients authorized to view that specific unit and pushes the update.
This flowchart demonstrates how different message types are routed through the system to ensure data consistency and immediate notification.
Sources: Documentación Técnica TAMV Online.pdf, Manual de Uso TAMV Online.pdf
Technical Specifications and Message Schema
The WebSocket server implements a standardized messaging protocol to ensure compatibility between different modules of the TAMV Online system.
Key Message Components
| Field | Type | Description |
|---|---|---|
event_type | String | Defines the action (e.g., POSITION_UPDATE, ALARM). |
timestamp | ISO8601 | The exact time the event was generated at the source. |
payload | Object | Contains the specific data relevant to the event. |
node_id | String | Unique identifier for the originating device or user. |
Server Configuration Parameters
| Parameter | Default Value | Description |
|---|---|---|
WS_PORT | 8080 | Port on which the WebSocket server listens. |
KEEPALIVE_INTERVAL | 30000ms | Frequency of heartbeat signals to detect dead connections. |
MAX_CONNECTIONS | 5000 | Maximum concurrent active WebSocket sessions. |
Sources: Documentación Técnica TAMV Online.pdf, package.json
Security and Error Handling
Security is handled via token-based authentication during the initial handshake. If a connection fails to provide a valid token or exceeds the KEEPALIVE_INTERVAL without a response, the server automatically terminates the session to conserve resources.
- Heartbeat Mechanism: The server sends a 'ping' frame every 30 seconds; clients must respond with a 'pong'.
- Error Recovery: Clients are instructed to implement an exponential backoff strategy for reconnection attempts to avoid DDoS-like behavior during server restarts.
Sources: Manual de Uso TAMV Online.pdf, Documentación Técnica TAMV Online.pdf