Overview of the Watson WebSocket Client Architecture
mainThe Watson WebSocket client is designed as a modern, async-first sibling library to the Watson server, packaged separately as Watson.Clients. Unlike older versions of WatsonWebsocket, the client does not use a hidden background receive loop. Instead, it follows a model where the consumer explicitly manages receiving messages, ensuring whole-message semantics and better lifecycle control.
Key architectural principles include:
- Async-First API: All core operations (
ConnectAsync,SendTextAsync,ReceiveAsync, etc.) are asynchronous. - Explicit Lifecycle: Connection and disconnection are explicit operations.
- Whole-Message Semantics: The client reassembles fragmented frames so that users receive complete messages rather than raw frames.
- Separation of Concerns: The client is a separate NuGet package (
Watson.Clients) to allow for different framework targeting (e.g.,netstandard2.0,net8.0) without constraining the server package.