Skip to content

About

Support for using WebSockets with happstack-server

Resources

Stars

4 stars

Watchers

3 watching

Forks

Repository files navigation

happstack-websockets

This library provides support for using WebSockets with Happstack.

The example directory contains an example echo server and client. The client is a bit lack luster at the moment. It sends a single request to the server and logs the response to console.

Clearly an example that looks like it is actually doing something would be nicer.

This library is mostly just a thin wrapper around the websockets library.

import Control.Monad (forever)
import Happstack.Server (dir, simpleHTTP, nullConf)
import Happstack.Server.WebSockets (runWebSocketsHappstack)
import qualified Network.WebSockets as WS

main = simpleHTTP nullConf $ dir "echo" (runWebSocketsHappstack echo)

echo :: WS.ServerApp
echo pending =
  do conn <- WS.acceptRequest pending
     forever (WS.receiveDataMessage conn >>= WS.sendDataMessage conn)

A request that is not for a websocket falls through to the next route. Each websocket is pinged every 25 seconds, so happstack-server's idle timeout does not drop it; runWebSocketsHappstackOptions changes that (wsPingInterval), e.g. for an app that pings on its own.

About

Support for using WebSockets with happstack-server

Resources

Stars

4 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages