WebSockets
supports bidirectional communication between a client and serverProject Forge provides a comprehensive WebSocket system that enables real-time, bidirectional communication between the server and client. The WebSocket implementation is designed for reliability, scalability, and ease of use, with automatic reconnection, message queuing, and robust error handling.
Overview
The WebSocket system offers: - Real-time Communication: Instant bidirectional messaging between server and client - Automatic Reconnection: Intelligent reconnection with exponential backoff - Message Queuing: Automatic queuing of messages when disconnected - Channel-based Routing: Organize communication using logical channels - Type-safe Messaging: Structured message format with TypeScript support - Debug Support: Built-in logging and debugging capabilities
Server-Side Implementation
Basic WebSocket Controller
Create a controller action to handle WebSocket upgrades:
1 | |
Advanced WebSocket Setup
For more complex scenarios with custom logic:
1 | |
Message Broadcasting
Send messages to connected clients:
1 | |
Client-Side Implementation
Set up a WebSocket connection on the client side:
1 | |
Message Format
1 | |
Security Considerations
Authentication and Authorization
Ensure WebSocket connections are properly authenticated:
1 | |