Converse Over a Channel
This is where things start to get interesting. So far, we’ve sent a join message and gotten an ok back, but channels support much richer forms of bidirectional communications between clients and the server. We’re going to take a closer look at the most common of these, and they will help us a lot through the rest of this chapter and while building your own applications.
The simplest way to send a message back from the server is to return a :reply tuple from the channel callback. This is a three-element tuple {:reply, some_response, socket}, where the middle element gets sent back to the client that originally sent the message. This should look really familiar after our work with GenServer.
Another way to talk back from ...
Get Functional Web Development with Elixir, OTP, and Phoenix now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.