I’ve been programming a websocket server using Network.WebSockets.
You start up a websockets server with runServer like this:
app :: Request -> WebSockets Hybi00 ()
app _ = app1
main :: IO ()
main = runServer "0.0.0.0" 8000 app
But I would really like the websockets server to run out of port 80 along with a normal Snap webserver.
Node.js is capable of doing this with Socket.io (see http://socket.io/#how-to-use on the left example).
Here is a Ruby library that achieves something similar: https://github.com/simulacre/sinatra-websocket
How would one do this in Haskell?
The websockets-snap package has a function:
runWebSocketsSnap :: Protocol p => (Request -> WebSockets p ()) -> Snap ()
This should let you use websockets from almost any place in your application. Here’s a simple example: