FSharp.FIO.WebSockets
0.4.0-beta
See the version list below for details.
dotnet add package FSharp.FIO.WebSockets --version 0.4.0-beta
NuGet\Install-Package FSharp.FIO.WebSockets -Version 0.4.0-beta
<PackageReference Include="FSharp.FIO.WebSockets" Version="0.4.0-beta" />
<PackageVersion Include="FSharp.FIO.WebSockets" Version="0.4.0-beta" />
<PackageReference Include="FSharp.FIO.WebSockets" />
paket add FSharp.FIO.WebSockets --version 0.4.0-beta
#r "nuget: FSharp.FIO.WebSockets, 0.4.0-beta"
#:package FSharp.FIO.WebSockets@0.4.0-beta
#addin nuget:?package=FSharp.FIO.WebSockets&version=0.4.0-beta&prerelease
#tool nuget:?package=FSharp.FIO.WebSockets&version=0.4.0-beta&prerelease
FIO.WebSockets
WebSockets for FIO. Open connections, send frames, and pattern
match on incoming messages as composable effects — connections are scoped and released for you,
and failures surface as a typed WsError rather than raw exceptions.
- Client —
WebSocketClient.connectDefaultopens a connection (dispose it withuse!), orwithConnectionStringscopes it and closes it for you - Server —
WebSocketServer.start/acceptDefault/closefor manual control, orWebSocketServer.serve/acceptLoopto run a handler per connection, stopping the listener when interrupted; accepted sockets expose the peer'sRemoteEndPointand theLocalEndPoint - Typed messages — match on
Frame(Text …)/Frame(Binary …)/ConnectionClosed - Custom codecs — send and receive typed payloads
Install
dotnet add package FSharp.FIO.WebSockets
Quick Start
open FIO.DSL
open FIO.WebSockets
open FIO.WebSockets.WebSocketExtensions
let client = fio {
use! ws = WebSocketClient.connectDefault "ws://localhost:8080/ws"
do! ws.SendString "Hello, server!"
return! ws.ReceiveString()
}
Server
open FIO.DSL
open FIO.WebSockets
let server = fio {
let! listener = WebSocketServer.start "http://localhost:8080/ws/"
let! webSocket = WebSocketServer.acceptDefault listener WebSocketConfig.defaultConfig
match! webSocket.ReceiveMessage() with
| Frame(Text text) -> do! webSocket.SendText $"echo: {text}"
| _ -> do! WebSocketServer.close listener
}
Errors
Operations fail with a typed WsError; each case says what went wrong, so a receive loop can decide
without inspecting messages:
| Case | Raised by |
|---|---|
Closed |
the peer closed (Receive with a codec, ReceiveString/ReceiveBytes/ReceiveJson), a send after the peer's close frame, or any send/receive/close on a socket that is already closed or aborted |
CodecError |
encoding or decoding a payload, including a frame of the wrong kind |
ReceiveFailed / SendFailed |
a transport fault while receiving or sending |
ConnectionFailed |
connecting, listening, or accepting |
TimeoutError |
the configured send or receive timeout elapsed |
MessageTooLarge |
a message exceeded MaxMessageSize |
GeneralError |
anything unclassified |
WsError.fromException / WsError.toException bridge raw exceptions. A chat-style loop that stops on
close and skips malformed messages is a CatchAll away:
socket.Receive(codec).Map(Message).CatchAll(function
| Closed _ -> FIO.succeed PeerClosed
| CodecError reason -> FIO.succeed (Unreadable reason)
| error -> FIO.fail error)
Closing
withConnection and acceptLoop close the socket for you, but only when it can still complete the
closing handshake. Interrupting a fiber that is blocked in ReceiveMessage — losing a race, Stop() —
aborts the connection instead. For a graceful close while a reader is pending, call Close from another
fiber first: it closes the outgoing side, and the pending receive then observes the peer's close frame as
ConnectionClosed.
The handshake waits for the peer's close frame, so Close is bounded by SendTimeout like a send: a
peer that has stopped reading makes it fail with TimeoutError and the connection is aborted, instead
of holding the finalizer — and with it an app's shutdown — open indefinitely.
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FSharp.Core (>= 10.1.401)
- FSharp.FIO (>= 0.4.0-beta)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.5.0-beta | 63 | 10/11/2026 |
| 0.4.0-beta | 90 | 9/17/2026 |
| 0.3.0-beta | 99 | 9/11/2026 |
| 0.2.2-beta | 92 | 7/12/2026 |
| 0.2.1-beta | 91 | 7/9/2026 |
| 0.2.0-beta | 84 | 7/6/2026 |
| 0.1.15-alpha | 89 | 6/30/2026 |
| 0.1.10-alpha | 86 | 6/24/2026 |
| 0.1.0-alpha | 110 | 6/18/2026 |