Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 1.17 KB

README.md

File metadata and controls

34 lines (25 loc) · 1.17 KB

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.