Hacker News new | ask | show | jobs
by phamilton 4134 days ago
Consuming data isn't hard. Creating a dashboard that displays the values sent down on an interval over a websocket is super easy.

Sending data isn't hard. Sending the mouse coordinates on a click to the server over a websocket is super easy.

There is, however, no easy way to consume data and send a response. To write an echo server, for example, you currently have to send the data to a javascript port and then read from the port to send it back.

2 comments

I ended up implementing this in JavaScript using Rx, but the core concept is the same:

    Incoming requests:     --a------------->
    Requests to server:    ---b------------>
    Responses from server: -----------d---->
    Updates to app state:  ---c--------e--->
a - User "sends message" to chat room

b - Handler for that action queues a request

c - Handler for that action also queues a local update

d - Server responds with the sent message

e - Handler for that response queues a local update

Yep, it was specifically when I wanted an application that would run a game loop involving round trips to the backend for every step that I ran into a lot of difficulty. Ports were not very clearly documented and I didn't find any examples, so I wound up writing Javascript instead.