The ghcjs-websockets package


ghcjs-websockets aims to provide an clean, idiomatic Haskell interface abstracting over the Javascript Websockets API, targeting ghcjs for receiving serialized tagged and untagged data.

The interface abstracts websockets as raw data streams and is designed to allow multiple styles of usage; in particular, is adapted for io-stream-style usage and distributed-process-style usage. It is designed to fit in unintrusively in larger frameworks, and adaptable for other interfaces (like pipes).

This library provides both tagged and untagged communication channels, using tagged-binary

Tagged channels mimic the behavior of Cloud Haskell and distributed-process, with their dynamic communication channels. You can use the same channel to send in polymorphic, typed data and deal with it at the time you wish.

Some examples:

 -- Echoes input from the server.
 main :: IO ()
 main = do
     c <- openConnection "ws://"
     forever $ do
         d <- withConn c expectText
         putStrLn d
         withConn c (sendText d)
     closeConnection c
 -- Echoes input from the server.
 main :: IO ()
 main = withUrl "ws://" . forever $ do
     d <- expectText
     liftIO $ putStrLn d
     sendText d
 -- Keep on printing all `Just` values, and stop at the
 -- first `Nothing`.
 whileJust :: ConnectionProcess ()
 whileJust = do
     d <- expect
     case d of
       Just d' -> do
           liftIO $ putStrLn d'
       Nothing ->
           return ()
 -- Server emits `Int`s or `String`s randomly; launch
 -- two parallel threads to catch the data as it comes
 -- in, one watching for `Int`s and one watching for
 -- `String`s.
 main :: IO ()
 main = do
    c <- openTaggedConnection "ws://"
    t1 <- forkIO . withConn c . forever $ do
        n <- expectTagged
        replicateM n . liftIO . putStrLn $ "got a number! " ++ show n
    t2 <- forkIO . withConn c . forever $ do
        s <- expectTagged
        liftIO $ putStrN s
    await t1
    await t2
    closeConnection c

See the JavaScript.WebSockets module for a more detailed introduction.

There is still some functionality left to be desired; feel free to open a ticket and send in suggestions or bugs, and all pull requests are welcomed!


Dependenciesbase (==4.7.*), binary, bytestring, containers, ghcjs-base, spoon, tagged-binary, text, transformers [details]
CopyrightCopyright (c) Justin Le 2014
AuthorJustin Le <>
MaintainerJustin Le <>
Home page
Source repositoryhead: git clone
UploadedThu Mar 13 07:13:55 UTC 2014 by jle



Maintainers' corner

For package maintainers and hackage trustees