ghcjs-websockets: GHCJS interface for the Javascript Websocket API

[ deprecated, library, mit, web ] [ Propose Tags ]

Documentation at

'ghcjs-websockets' aims to provide a clean, idiomatic, efficient, low-level, out-of-your-way, bare bones, concurrency-aware interface with minimal abstractions over the Javascript Websockets API, inspired by common Haskell idioms found in libraries like 'io-stream' and the server-side websockets library, targeting compilation to Javascript with ghcjs.

The interface asbtracts websockets as simple IO/file handles, with additional access to the natively "typed" (text vs binary) nature of the Javascript Websockets API. There are also convenience functions to directly decode serialized data (serialized with binary sent through channels.

The library is mostly intended to be a low-level FFI library, with the hopes that other, more advanced libraries maybe build on the low-level FFI bindings in order to provide more advanced and powerful abstractions. Most design decisions were made with the intent of keeping things as simple as possible in order for future libraries to abstract over it.

Most of the necessary functionality is in hopefully in JavaScript.WebSockets; more of the low-level API is exposed in JavaScript.WebSockets.Internal if you need it for library construction.

See the JavaScript.WebSockets module for detailed usage instructions and examples.

Some examples:

import Data.Text (unpack)

-- A simple echo client, echoing all incoming text data
main :: IO ()
main = withUrl "ws://" $ \conn ->
    forever $ do
        t <- receiveText conn
        putStrLn (unpack t)
        sendText conn t
-- A simple client waiting for connections and outputting the running sum
main :: IO ()
main = withUrl "ws://" (runningSum 0)

runningSum :: Int -> Connection -> IO ()
runningSum n conn = do
    i <- receiveData conn
    print (n + i)
    runningSum (n + i) conn
-- Act as a relay between two servers
main :: IO ()
main = do
    conn1 <- openConnection "ws://"
    conn2 <- openConnection "ws://"
    forever $ do
        msg <- receiveMessage conn1
        sendMessage conn2 msg
    closeConnection conn2
    closeConnection conn1


[Last Documentation]

  • JavaScript
    • JavaScript.WebSockets
      • JavaScript.WebSockets.Internal


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,, (info)
Dependencies base (>=4.7 && <5), base64-bytestring (>=1), binary (>=0.7), bytestring (>=0.10), ghcjs-base (>=0.1), text (>=1.2) [details]
License MIT
Copyright Copyright (c) Justin Le 2015
Author Justin Le <>
Maintainer Justin Le <>
Revised Revision 1 made by jle at 2015-05-11T09:50:45Z
Category Web
Home page
Source repo head: git clone
Uploaded by jle at 2015-05-11T09:24:31Z
Distributions NixOS:
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3588 total (27 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 2016-12-09 [all 7 reports]