4

In Haste, is it possible to call into client side code with RPC from the server just like it is possible to call into the server side code from the client side? E.g. to broadcast a message that someone has entered in a chatroom to all participants.

In here I see a similar example is implemented, the way I understand it — with a technique similar to long polling; the client requests, and the server blocks sending a response until it has some to send; then the client requests again and so on.

But is it not possible to simply send something out without the client requesting it?

Wizek
  • 4,854
  • 2
  • 25
  • 52
  • I would abstract the comm. layer out, model 2-way communication algebraically, in a way that is agnostic of whether it happens in memory or crosses the HTTP barrier, and therefore the Haskell-JS barrier. Then, you can just write an "interpreter" for this algebra that chooses the appropriate communication implementation, such as long polling. Haste should be capable enough for this; if not, there's GHCJS. – Erik Kaplun Jan 17 '16 at 20:56
  • Do I understand correctly that your comment is about a general communication layer abstraction between server and client? Because if so, that could make sense. However, for now, I am getting acquainted with Haste, which already implements a layer on top of WebSockets. And WebSockets AFAIU are full-duplex, meaning it should be very much possible for the server to send data to the client, but I am not seeing how I can do that using the API provided by Haste, hence my original question. – Wizek Jan 17 '16 at 21:03
  • Yeah, my comment was quite high level. – Erik Kaplun Jan 17 '16 at 22:34

1 Answers1

1

So far I have never used it, but look into html5 web-sockets.

This provides a way for full-duplex communication, meaning your client can initiate communication to the server and vice versa. Hence the client does not need to poll every second anymore to see if a message is available at the server-side.

  • 2
    Thanks for the input! Yes, I'm already using a library build on top of WebSockets. See this comment of mine for some more details: http://stackoverflow.com/questions/34843524/in-haste-is-it-possible-to-call-into-client-side-code-with-rpc-from-the-server?noredirect=1#comment57427947_34843524 – Wizek Jan 17 '16 at 21:06
  • You're welcome. I see our messages crossed each other. Regarding socket-communication specifically within Haste I cannot help you. Hope you find the answer soon! –  Jan 17 '16 at 21:15