effectful-websockets: WebSocket connections as an Effectful effect

[ bsd3, control, library, network, web ] [ Propose Tags ] [ Report a vulnerability ]

A WebSocket effect for Effectful: send and receive whole text or binary messages, as single actions or as a Streamly stream. The client interpreter runs over the streamly-websockets package, keeps the action in the calling thread, and watches the connection with pings.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies async (>=2.2 && <2.3), base (>=4.19 && <4.22), bytestring (>=0.12 && <0.13), effectful-core (>=2.7.1 && <2.8), stm (>=2.5 && <2.6), streamly-core (>=0.3.3 && <0.4), streamly-http (>=0.1 && <0.2), streamly-websockets (>=0.1 && <0.2), text (>=2.1 && <2.2) [details]
Tested with ghc ==9.8.4 || ==9.10.3 || ==9.12.4
License BSD-3-Clause
Author Xavier Dectot
Maintainer Xavier Dectot <xavier@wheredoibegin.fr>
Uploaded by GdeVolpiano at 2026-11-28T12:06:14Z
Category Network, Web, Control
Home page https://github.com/GuillaumedeVolpiano/effectful-websockets
Source repo head: git clone https://github.com/GuillaumedeVolpiano/effectful-websockets.git
Distributions
Reverse Dependencies 2 direct, 1 indirect [details]
Downloads 4 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2026-11-28 [all 1 reports]

Readme for effectful-websockets-0.1.0.0

[back to package description]

effectful-websockets

A WebSocket connection as an Effectful effect.

  • Effectful.WebSocket: the WebSocket effect. Send and receive whole text or binary messages, one at a time or as a Streamly stream (messages). runWebSocketWith interprets it with two actions, for tests; traced reports every message to an observer, whatever the interpreter.
  • Effectful.WebSocket.Client: runWebSocketClient opens a connection with the streamly-websockets package and runs an action over it.
{-# LANGUAGE OverloadedStrings #-}

import Effectful (Eff, IOE, (:>))
import Effectful.Error.Static (Error)
import Effectful.WebSocket (Message, receiveMessage, sendText)
import Effectful.WebSocket.Client (WebSocketError, clientConfig,
                                   runWebSocketClient)

hello :: (IOE :> es, Error WebSocketError :> es) => Eff es (Maybe Message)
hello = runWebSocketClient (clientConfig "127.0.0.1" 8080 "/") $ do
  _ <- sendText "hello"
  receiveMessage

Behaviour

  • The action runs in the calling thread, so effects with thread-local state keep its changes. The pings are sent by a watchdog thread.
  • The server is pinged every ten seconds by default, with twenty seconds to answer; NoPong reports a silent server. Pongs are only seen while the action receives messages.
  • Sending from several threads at once is safe: each message goes out whole.
  • A connection closed by the server is not an error: receiving returns Nothing, and sending then returns False.
  • When the action is done, the client closes the WebSocket and waits for the server to answer (one second by default) before the TCP connection goes, so that the server reads all that was sent.
  • Plain TCP only. Secure WebSockets (wss://) are in effectful-websockets-tls, a package apart, so that this one does not need a TLS stack.

A server that breaks the protocol, or sends a message larger than maxMessageSize, ends the connection like a server that closes it.

To build against copies of streamly-websockets and streamly-http checked out next to this repository, pass --project-file=cabal.project.siblings.

Tested with GHC 9.8.4, 9.10.3 and 9.12.4, and effectful 2.7.1, against the server of streamly-websockets.

License

BSD-3-Clause. See LICENSE.