The ws-chans package

[Tags:bsd3, library, test]

Use Control.Concurrent.Chan.Unagi as an interface to a websocket server


[Skip to Readme]

Properties

Versions 0.1.0.0
Dependencies async, base (>=4.7 && <5), network, unagi-chan (>=0.4), websockets [details]
License BSD3
Copyright 2017 David Smith
Author David Smith
Maintainer david.smith@keemail.me
Category Network
Home page https://github.com/shmish111/ws-chans
Source repository head: git clone https://github.com/shmish111/ws-chans
Uploaded Sun Apr 9 21:59:21 UTC 2017 by shmish111
Distributions NixOS:0.1.0.0
Downloads 34 total (34 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-04-09 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for ws-chans

Readme for ws-chans-0.1.0.0

ws-chans

Build Status

Websockets represent a channel between a client and a server. ws-chans carries this concept deeper into your code by setting up an Control.Concurrent.Chan.Unagi.InChan and an Control.Concurrent.Chan.Unagi.OutChan as an interface to a websocket server. To send a message to the server you simply write a message to the InChan. To receive a message from the server you read from the OutChan.

The tests are probably the best place to look at some example usage but basically:

import           Control.Monad                        (forM, forever)
import           Data.Text                            (Text)
import           Network.WebSockets.Chan.Unagi        as Unagi

example :: IO [Text]
example = do
    (ic, oc, cic) <- Unagi.newChans "localhost" 8080 "" :: IO (Unagi.InChan Text, Unagi.OutChan Text, Unagi.InChan Text)
    Unagi.writeList2Chan ic msgs
    res <- forM msgs (\_ -> Unagi.readChan oc)
    Unagi.writeChan cic ("finished" :: Text)
    return res

newChans returns a tuple of:

  • an InChan which you write messages to, these will be sent to the websocket server
  • an OutChan which you read messages from, these are messages that have come from the websocket server
  • an InChan for closing the connection. This should have the same type as the first InChan. When you write a message to this InChan it will tell the server that you wish to close the connection. See the source code and Network.WebSockets.sendClose for more information on how this works.