streamly-websockets: WebSocket clients and servers written with Streamly

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

WebSockets (RFC 6455) over plain TCP, for clients and for servers. The opening handshake goes through streamly-http, frames are read with flatparse parsers from the stream of byte arrays of the connection, and the messages received are a stream. Pings are answered, fragmented messages put together, and the closing handshake done. TLS through a transport of the caller; no extension.


[Skip to Readme]

Modules

  • Streamly
    • External
      • Network
        • Streamly.External.Network.WebSocket
          • Streamly.External.Network.WebSocket.Frame
          • Streamly.External.Network.WebSocket.Handshake
          • Streamly.External.Network.WebSocket.Server

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 base (>=4.19 && <4.22), base64-bytestring (>=1.2 && <1.3), bytestring (>=0.12 && <0.13), cryptohash-sha1 (>=0.11 && <0.12), entropy (>=0.4 && <0.5), flatparse (>=0.5 && <0.6), network (>=3.2 && <3.3), stm (>=2.5 && <2.6), streamly-bytestring (>=0.2.3 && <0.3), streamly-core (>=0.3.3 && <0.4), streamly-flatparse (>=0.1 && <0.2), streamly-http (>=0.1 && <0.2), streamly-network-tcp (>=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-28T10:53:32Z
Category Network, Web, Streamly
Home page https://github.com/GuillaumedeVolpiano/streamly-websockets
Source repo head: git clone https://github.com/GuillaumedeVolpiano/streamly-websockets.git
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2026-11-28 [all 1 reports]

Readme for streamly-websockets-0.1.0.0

[back to package description]

streamly-websockets

WebSockets (RFC 6455) written with Streamly, over plain TCP, for clients and for servers. The opening handshake goes through streamly-http; frames are read with flatparse parsers from the stream of byte arrays of the connection; the messages received are a stream.

A client:

{-# LANGUAGE OverloadedStrings #-}

import Streamly.Data.Fold (drainMapM)
import Streamly.Data.Stream (fold)
import Streamly.Data.Stream qualified as S (take)
import Streamly.External.Network.WebSocket (Message (TextMessage), config,
                                            messages, send, withConnection)

main :: IO ()
main = withConnection (config "127.0.0.1" 9330 "/api") $ \connection -> do
  send connection (TextMessage "hello")
  fold (drainMapM print) (S.take 3 (messages connection))

A server that sends back what it receives:

{-# LANGUAGE OverloadedStrings #-}

import Streamly.Data.Fold (drainMapM)
import Streamly.Data.Stream (fold)
import Streamly.External.Network.WebSocket.Server (defaultServerOptions,
                                                   messages, send, serve)

main :: IO ()
main = serve "127.0.0.1" 8080 defaultServerOptions $ \_ connection ->
  fold (drainMapM (send connection)) (messages connection)

What it does

  • Text and binary messages, sent in one frame each, received whole even when the other side fragments them. Text is checked to be UTF-8.
  • Pings of the other side are answered, the pongs to ping counted (pongCount, in STM), and the closing handshake is done, all while messages are received.
  • Sending is safe from several threads. Receiving is for one thread at a time.
  • A limit on the size of a message (maxMessageSize) and on the time to open the connection (openTimeout).

Modules

  • Streamly.External.Network.WebSocket: the client.
  • Streamly.External.Network.WebSocket.Server: the server. Each client is served in a thread of its own; every upgrade asked properly is accepted.
  • Streamly.External.Network.WebSocket.Frame: frames, written and read.
  • Streamly.External.Network.WebSocket.Handshake: the opening handshake.

Limits of this version

  • TLS is not built in: withConnectionOver and acceptOver take a connection opened by other means, as a Transport of streamly-http. streamly-websockets-tls does it for both sides: wss:// URLs for clients, servers over TLS.
  • No extension (no compression) and no subprotocol negotiation.
  • Messages are sent in one frame; there is no streaming of a message.

Building

To build against copies of the libraries this package is built on (streamly-http, streamly-network-tcp, streamly-flatparse) checked out next to this repository, pass --project-file=cabal.project.siblings.