A full-stack WebSharper application that streams data from the server to the browser over a WebSocket and plots it as a live line chart with Chart.js.
- Server —
WebSocketChart/WebSocketServer.fsdefines a typedStatefulAgentthat pushes a new random number to the client every second on the/wsendpoint. - Client —
WebSocketChart/WebSocketClient.fsconnects to/wswith a plainWebSharper.JavaScript.WebSocket, decodes the JSON messages, and feeds each value into anEvent<string * float>that drives the chart. It also logs every message next to the chart. - Page —
WebSocketChart/Website.fsis a server-rendered sitelet that hosts the client entry point;WebSocketChart/Main.htmlis its template.
dotnet run --project WebSocketChart
Then open http://localhost:5350.
The app runs on port 5350, not the ASP.NET Core default 5000: on macOS, AirPlay Receiver listens on 5000 and answers browser requests with
403 Forbidden. The port comes fromWebSocketChart/Properties/launchSettings.json; override it withASPNETCORE_URLSif you prefer.
dotnet build WebSocketChart/WebSocketChart.fsproj -c Release
Main.htmlcontains an import map forchart.js/auto— the one bare module specifier thatWebSharper.Chartingemits. The client is served as native ES modules, so no bundler is needed.- The project targets .NET 10 and WebSharper 10 and no longer uses Paket.
Every push to master and every pull request builds the app in Release via
.github/workflows/build.yml. Being a server + WebSocket app, it is not
deployed to gh-pages.
