Understanding channels

As mentioned previously, channels are the in-between for sockets and topics. They essentially act as the controllers of the Phoenix real-time application puzzle. The easiest way for us to really understand this is to dive right into the code and start messing around with things until they break!

Phoenix provides a set of macros for us to use with channels, much in the same way it does for controllers (via use VocialWeb, :controller) or with views (via use VocialWeb, :view). We'll create a new file at lib/vocial_web/channels/polls_channel.ex:

defmodule VocialWeb.PollsChannel do  use VocialWeb, :channelend

Notice that here we're using the :channel macro instead of :controller or :view or anything like that! Next, we'll ...

Get Phoenix Web Development 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.