Question

I'm wondering if someone could explain the differences between the Haskell websocket libraries and how they work with Yesod.

The two main examples I'm going off are this tutorial for Network.Websockets and the wai websockets package.

I haven't been able to find a good example or tutorial for the wai package. Since yesod uses wai, what advantages does it have over the simple network one? Is it meant to be used instead of, or inconjunction with Network.Websockets?

I've seen examples, but I haven't been able to understand how they actually fit into the yesod environment. If somebody could explain how websockets relate to handlers and IO and such in Yesod, that would be great.

Note: I have seen this question and this question but I can't understand how to apply them, as they don't actually explain where websockets fit into Yesod.

Was it helpful?

Solution

Yesod websockets are now available. "cabal install yesod-websockets" fetches and installs the package. You can read about it at on Michael Snoyman's March 9, 2014 blog at http://www.yesodweb.com/blog/2014/03/wai-yesod-websockets.

OTHER TIPS

The fact is that websockets fall outside the scope of normal request/response pairs. As such, normal Yesod handlers are not able to simply start using websockets. That would be ideal, and perhaps we'll add that support in the future, but I haven't figured out a way to do it yet (ideas/suggestions/discussion are highly welcome!).

In the meanwhile, the way to integrate websockets is to drop down a layer of abstraction and use wai-websockets directly with Warp. The answers you link to describe how to get that done.

I'm not sure what your requirements are, but eventsource fits into the existing request/response paradigm much better, and the yesod-eventsource package makes it easy to integrate with Yesod. So if that fulfills your requirements, you may want to check it out. (Eventsource also has the advantage that it works correctly with HTTP reverse proxying.)

UPDATE This answer is no longer accurate; please see David's answer for updated information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top