Recommended solutions for real-time apps

33 views
Skip to first unread message

Nolan Darilek

unread,
Aug 11, 2014, 11:59:49 PM8/11/14
to ha...@googlegroups.com
Hello,

I'm investigating using Happstack in a real-time app. I'd like to push
updates to users via web sockets or some other mechanism.

Google doesn't immediately show me a solution for this. I realize
Happstack itself doesn't care what I use, but as someone fairly new to
Haskell I'm wondering if there's a recommended library for this?

I don't care much about the mechanism, though I'd rather avoid rapid
polling. I just want to communicate between the client and server when
things change.

Thanks.

Adam Bergmark

unread,
Aug 12, 2014, 7:54:05 AM8/12/14
to ha...@googlegroups.com
Hi Nolan, you may be interested in socket-io [1] or websockets [2]. I haven't tried them though!


- Adam





--
You received this message because you are subscribed to the Google Groups "HAppS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to happs+unsubscribe@googlegroups.com.
To post to this group, send email to ha...@googlegroups.com.
Visit this group at http://groups.google.com/group/happs.
For more options, visit https://groups.google.com/d/optout.

Nolan Darilek

unread,
Aug 12, 2014, 4:36:01 PM8/12/14
to ha...@googlegroups.com
Cool, didn't realize there was a socket.io port.

I'm fairly new to Haskell (as in, did the intro thing a decade and a half ago in college, was familiar with the syntax but am only recently tackling understanding monads and the like.) Has anyone gotten this working with Happstack? As in, plugged a socket.io server into the Happstack routing table?

There are so many moving parts that I'm not sure where to begin. At the moment I'm doing something like:

main = do
    updateGlobalLogger rootLoggerName (setLevel INFO)
    simpleHTTP nullConf $ msum
        [ dir "favicon.ico" $ notFound (toResponse ()),
        serveDirectory DisableBrowsing [] "www",
        implSite (pack "") (pack "/api") api,
        implSite (pack "") (pack "") site
        ]

I'd like to put socket.io under the /api site, but I'm not sure if that's practical. There's an initialize function that looks like so:

This computation initializes a Socket.IO server and /returns/ a computation that
you should call whenever a request comes in to the @/socket.io/@ path. For
example, in a Snap application, you might do:

> handler <- initialize snapAPI mkRoutes
> quickHttpServe $ route [("/socket.io", handler)]

The second argument to this function is an action to build up the routing table,
which determines what happens when clients emit events. It is also an action
that is called every time a client connects, so you can mutate state by taking
advantage of the 'MonadIO' instance. You can build a routing table by using the
convenience 'on' family of functions.

-}
initialize
  :: MonadIO m
  => EIO.ServerAPI m
  -> StateT RoutingTable m a
  -> IO (m ())
initialize api socketHandler = do
...

So I'm guessing something needs to be an instance of EIO.ServerAPI, but I'm not sure if that's my API type for routes or something else. I'm also guessing the result of the initialize call gets plugged into the routing table like my other subsites, meaning it needs to be an instance of some other type?

Anyhow, if anyone has gotten socket.io glued to Happstack, it might be easier for me to learn state monads and such by writing code to statefully track user connects/disconnects than it is for me to figure out how this goes together. :)


On 8/12/2014 6:54 AM, Adam Bergmark wrote:
Hi Nolan, you may be interested in socket-io [1] or websockets [2]. I haven't tried them though!


- Adam

On Sat, Aug 9, 2014 at 8:50 PM, Nolan Darilek <no...@thewordnerd.info> wrote:
Hello,

I'm investigating using Happstack in a real-time app. I'd like to push updates to users via web sockets or some other mechanism.

Google doesn't immediately show me a solution for this. I realize Happstack itself doesn't care what I use, but as someone fairly new to Haskell I'm wondering if there's a recommended library for this?

I don't care much about the mechanism, though I'd rather avoid rapid polling. I just want to communicate between the client and server when things change.

Thanks.


--
You received this message because you are subscribed to the Google Groups "HAppS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to happs+un...@googlegroups.com.

To post to this group, send email to ha...@googlegroups.com.
Visit this group at http://groups.google.com/group/happs.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "HAppS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to happs+un...@googlegroups.com.

To post to this group, send email to ha...@googlegroups.com.
Visit this group at http://groups.google.com/group/happs.
For more options, visit https://groups.google.com/d/optout.
!DSPAM:53ea0077212172943850843!

Reply all
Reply to author
Forward
0 new messages